Repository navigation
Two easy performance wins - #166
Merged
Merged
Conversation
`addParent` is called quite a lot during the import process (about 10 times per record) and each time it does string manipulation to calculate property names, and binds two newly created functions. It turns out by not doing those two things we can save somewhere around 3-5% of the work the importer does per record in the main thread, so a pretty nice gain basically for free.
These requires running on each new Document call just waste cycles, in my testing it's about a 1% savings in main thread CPU time to hoist them out.
missinglink
reviewed
Sep 21, 2026
| this.addPostProcessingScript( require('./post/patch') ); | ||
| // create a non-enumerable property for post-processing scripts, | ||
| // seeded with a copy of the defaults so it stays writable per document | ||
| Object.defineProperty( this, '_post', { writable: true, value: defaultPostProcessingScripts.slice() }); |
Member
There was a problem hiding this comment.
Interesting, I'm surprised this is so much less expensive considering calls to require() are cached.
Member
There was a problem hiding this comment.
Member
Author
There was a problem hiding this comment.
Right, I don't think the required module itself is executed, parsed, or anything like that again (we'd notice and the change would be huge). But it makes sense there would be some machinery that runs every time you call require, no matter what.
The measured difference is pretty small, about 1 microsecond averaged over a few million documents. It's measurable but only just. Still, that's about 1% of the time spent on each document.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Two easy performance wins that help all our importers:
requirecalls out ofDocumentconstructor. This is the smaller one but it saves about 1% of the time an importer spends on a single record based on my testing.addParent. This is the bigger one, my testing shows 5% speedup from this alone. We calladdParentseveral times perDocument, so simplifying here really speeds things up!