Skip to content

Commit

Permalink
reduce memory allocation in label ids (use numbers instead of strings)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcamper committed Mar 6, 2019
1 parent 9d772cd commit af89f8e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/labels/label.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ Label.add = function (label, bboxes) {
};

Label.id = 0;
Label.id_prefix = ''; // id prefix scoped to worker thread
Label.id_prefix = 0; // id prefix scoped to worker thread
Label.id_multiplier = 0; // multiplier to keep label ids distinct across threads

Label.nextLabelId = function () {
return Label.id_prefix + '/' + (Label.id++);
return Label.id_prefix + ((Label.id++) * Label.id_multiplier);
};

Label.epsilon = 0.9999; // tolerance around collision boxes, prevent perfectly adjacent objects from colliding
Expand Down
1 change: 1 addition & 0 deletions src/scene/scene_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const SceneWorker = Object.assign(self, {
this.style_manager = new StyleManager();
this.importExternalScripts(external_scripts);
Label.id_prefix = worker_id;
Label.id_multiplier = num_workers;
return worker_id;
},

Expand Down

0 comments on commit af89f8e

Please sign in to comment.