Optimise the Inline Requires plugin #9664
Merged
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.
↪️ Pull Request
In our large application build, the Inline Requires plugin adds about 25% to the build time (6 min) - so we have looked at some quick optimisation wins.
While the ideal solution for inline requires would be to implement it in the
ScopeHoistingPackager
, a good time to do that would be when we move the packager to native code rather than working on a complex change to it now.With a combination of tracing, profiling, and eyeballing (thanks @yamadapc!) we identified a few small performance improvements to the current implementation
if
(this saves some GC overhead and provides a 10-15% perf improvement in our tests)verbose
logging - even when not logging, there was still significant overhead from this due to the volume (another 10-15%)The main contributor now to this plugin's run time is the SWC
print
of the AST back to JS. We have considered a couple of other potential optimisations (that really still just avoid moving the code into the pacakger where it should be...):parse
/print
pattern.print
/parse
that plugin has to do.🚨 Test instructions
Verified application still works (unit tests for the visitor pass)
✔️ PR Todo