You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched and referenced existing issues, feature requests and discussions
I am filing a FEATURE request.
Description
While profiling, I noticed there is an easy performance win within _fireSelectionEvents. This function shows up in profiling when you are selecting/deselecting a large number of objects (low 1000s). Right now, it determines what is added and what is removed by looping each array and checking if the object exists in the other array. If the existence check was against a set instead of searching the whole list, the performance would be improved, especially when you have large numbers of objects.
I don't have time to do a PR, but I think it would look something like this:
let somethingChanged = false,
invalidate = false;
const objects = this.getActiveObjects(),
added: FabricObject[] = [],
removed: FabricObject[] = [];
const objectsSet = new Set(objects);
const oldObjectsSet = new Set(oldObjects);
oldObjects.forEach((target) => {
if (!objectsSet.has(target)) {
somethingChanged = true;
target.fire('deselected', {
e,
target,
});
removed.push(target);
}
});
objects.forEach((target) => {
if (!oldObjectsSet.has(target)) {
somethingChanged = true;
target.fire('selected', {
e,
target,
});
added.push(target);
}
});
Current State
Works, but slow for large numbers of objects.
Thanks!
Additional Context
No response
The text was updated successfully, but these errors were encountered:
CheckList
Description
While profiling, I noticed there is an easy performance win within
_fireSelectionEvents
. This function shows up in profiling when you are selecting/deselecting a large number of objects (low 1000s). Right now, it determines what is added and what is removed by looping each array and checking if the object exists in the other array. If the existence check was against a set instead of searching the whole list, the performance would be improved, especially when you have large numbers of objects.I don't have time to do a PR, but I think it would look something like this:
Current State
Works, but slow for large numbers of objects.
Thanks!
Additional Context
No response
The text was updated successfully, but these errors were encountered: