perf: apply optional chaining and an arguments->args change #561
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.
👋 hi! I just learned about this repo's performance challenge. Very fun. It's pretty optimized as-it-is, so most things I tried didn't result in any positive impact in
goober.modern.js
after gzipping locally.But, I did find two changes that each showed small improvements locally:
wrapper
function withinstyled.js
, switching thelet _args = arguments
to a modern...args
rest (thereby also changing the function to an=>
arrow lambda)?.
optional chaining as syntax sugar indist/goober.modern.js
whenever possible, as optional chaining is supported in modern environments per caniuse's optional chaining query and kangax's optional chaining rowFiles created by running:
npm run build
gzip dist/goober.modern.js --best
Measurements taken by opening Get Info on Mac.
goober.modern.js
goober.modern.js.gz
.gz
Δ (bytes)_args
?.
_args
and?.
Note: Optional chaining is implemented right now with typescript-eslint's
@typescript-eslint/prefer-optional-chain
. Which is a very silly, over-the-top way to get this to work... but all the alternatives I'd tried didn't work!src/
files and adding'@babel/plugin-syntax-logical-assignment-operators'
tobabel.config.cjs
, but even after updating to the latest@babel/*
packages, it kept transpiling down tonull==...
checks indist/
g && g()
in the output (blocked onsome.object && some.object.fn()
andthis.object && this.object.value
not handled villesau/optional-chaining-codemod#51)If you know a way to get optional chaining to work in an output bundle without installing four dev dependencies, please let me know!