Skip to content
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

perf: apply optional chaining and an arguments->args change #561

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JoshuaKGoldberg
Copy link

@JoshuaKGoldberg JoshuaKGoldberg commented Aug 13, 2023

👋 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:

  • In the wrapper function within styled.js, switching the let _args = arguments to a modern ...args rest (thereby also changing the function to an => arrow lambda)
  • Using ?. optional chaining as syntax sugar in dist/goober.modern.js whenever possible, as optional chaining is supported in modern environments per caniuse's optional chaining query and kangax's optional chaining row

Files created by running:

  1. npm run build
  2. gzip dist/goober.modern.js --best

Measurements taken by opening Get Info on Mac.

Change(s) goober.modern.js goober.modern.js.gz .gz Δ (bytes)
(baseline) 2,284 bytes 1,269 bytes (n/a)
Just _args 2,261 bytes 1,263 bytes -6 🟢
Just ?. 2,269 bytes 1,263 bytes -6 🟢
_args and ?. 2,250 bytes 1,260 bytes -9 🟢

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!

If you know a way to get optional chaining to work in an output bundle without installing four dev dependencies, please let me know!

@vercel
Copy link

vercel bot commented Aug 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
goober-rocks ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 13, 2023 4:21am

@JoshuaKGoldberg
Copy link
Author

Ping @cristianbote, is the challenge still active? I enjoyed this PR, but it did take some time to get to. If this repo isn't active anymore I'd think it'd be best to make that clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant