New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize AssetRegistry
class
#5457
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
such a huge improvement!
Co-authored-by: Donovan Hutchence <slimbuck7@gmail.com>
Co-authored-by: Donovan Hutchence <slimbuck7@gmail.com>
👏🏻 |
Looks like it was inneficient build of names-asset index, which was using indices within list of assets instead of ID's of assets. How does this perform on projects with thousands of assets? I'm afraid it can be slower and lead to GC stalls. |
@Maksims |
IMO it's a generic issue with Edit: Just made up a quick polyfill, without testing too much, but the principle should be clear: Set.prototype.filter = function(test) {
const ret = [];
this.forEach((val, idx, set) => {
if (test(val, idx, set)) {
ret.push(val);
}
});
return ret;
}
const nums = new Set([1, 2, 3, 4, 5, 6, 7, 8]);
nums.filter(_ => _ > 5); Edit 2: found something official: https://github.com/tc39/proposal-collection-methods IMO we should aim for a polyfill for this (less GC). |
* Optimize AssetRegistry class * Update src/framework/asset/asset-registry.js Co-authored-by: Donovan Hutchence <slimbuck7@gmail.com> * Update src/framework/asset/asset-registry.js Co-authored-by: Donovan Hutchence <slimbuck7@gmail.com> * if consistency * null -> undefined * Lint fixes * Improve docs * Restore return of null for find --------- Co-authored-by: Donovan Hutchence <slimbuck7@gmail.com>
_assets is not longer browsable, any way to retrieve the list manually? |
|
Coming back to optimizations, unfortunately lack of indexing lead to major performance regression when using |
You're calling |
I guess the |
The particular project has a loader for custom level format and uses names of assets for referencing. And during loading it takes significantly longer to find all assets due to this performance regression. |
Wanna do a PR? 😉 |
|
The
AssetRegistry
class is incredibly inefficient. This PR massively optimizes it.Before (~62ms to collapse a node in the 3D Tiles engine):
After (~3ms to collapse a node in the 3D Tiles engine):
Note, there is an API change here.
AssetRegistry#find
now returnsundefined
instead ofnull
if no match is found. This matches howArray#find
works.I confirm I have read the contributing guidelines and signed the Contributor License Agreement.