Skip to content

Commit

Permalink
Merge pull request #1194 from OpenGeoscience/reduce-memory-copies
Browse files Browse the repository at this point in the history
perf: Reduce memory copy on pixelmap layer creation.
  • Loading branch information
manthey authored Apr 4, 2022
2 parents 61e14b9 + 613abc2 commit b5206cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pixelmapLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ var pixelmapLayer = function (arg) {
return new pixelmapLayer(arg);
}
arg = arg || {};
/* Don't extend data from args -- it can be very slow */
let argdata;
if (arg.data) {
argdata = arg.data;
delete arg.data;
}
arg = $.extend(
true,
{},
Expand Down Expand Up @@ -99,8 +105,8 @@ var pixelmapLayer = function (arg) {
pixelmapArgs.color = arg.color;
}
m_pixelmapFeature = m_this.createFeature('pixelmap', pixelmapArgs);
if (arg.data) {
m_pixelmapFeature.data(arg.data);
if (argdata) {
m_pixelmapFeature.data(argdata);
}
m_this.style = m_pixelmapFeature.style;
m_this.data = m_pixelmapFeature.data;
Expand Down
5 changes: 5 additions & 0 deletions src/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,12 @@ util.createLayer = function (name, map, arg) {
options.features = layerDefaultFeatures[name];
}
if (arg !== undefined) {
const argdata = arg.data;
delete arg.data;
$.extend(true, options, arg);
if (argdata) {
options.data = argdata;
}
}
layer = layers[name](options);
layer.layerName = name;
Expand Down

0 comments on commit b5206cc

Please sign in to comment.