LDrawLoader: parallelize parts library downloads to improve load times #22253
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Merge #22249 first
Description
This PR focuses on parallelizing file downloads when loading models from the LDraw Parts Library. There's a lot of rearranging that happened so the diff looks pretty large. The big changes are:
processObjecthave been removed because promises simplify things.finalizeObjecthas been changed to take the parseScope to finalize and moved to be a class function so the parent scope can guarantee the objects are processed in the right order to avoid messing up the construction steps.With this change loading the Imperial Star Destroyer Lego model goes from a load time of a little over 4 minutes down to around 1 minute 25 seconds. I think there is still room for improvement to be had by caching the parsed file contents rather than parsing the text content over and over every time a file is reused (which might be one of my upcoming PRs 😁).
@mrdoob This PR adds a few arrow functions to the class -- I'm not sure what you're feelings are on using them in the project but generally I find them to be easier to look at and simplify things when working with an outer "this" pointer. If you'd like me to remove them let me know.
For testing you can check out the live link to the ldraw example here (which still is just using the prepacked models).
cc @yomboprime