-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Code golf preact.js.gz size down by 53 B ⛳️ #1599
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All I can say is Wow :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is just... holy moly! I'd love to have @developit take a look at .some()
vs the for
loops. In my microbenchmarks (I may be doing them wrong) they are faster, but our lord of the benches can likely clear that one up :)
The code used to check whether newProps is falsy, but before that Object.keys(newProps) would have crashed before that.
`undefined` is falsy anyway.
Rebased the code on master, removed a couple of commits that used |
Accidentally closed from mobile GitHub. Sorry! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The benches were settled in slack 🥇 💯 This PR is really awesome! Starting from the detailed commits, to all the benches and all. It's just on a whole other level 👍 👍
This pull request applies a bunch of small code modifications that seem to reduce the overall bundle size. Here's a rough outline of the changes:
Array#map
call withArray#some
that:Array#map
but doesn't collect all callback results to an array likeArray#map
Array#forEach
createContext
extensively, getting rid of local variable and function declarations.newProps
's falsyness is checked although that shouldn't be possible at that point.isNew
tofalse
, as its defaultundefined
value is sufficient.if (x!=null)
checks toif (x)
when appropriate.The performance seems to stay on the same level with master. I used Chrome 74, MacOS 10.14.4 and https://github.com/mathieuancelin/js-repaint-perfs for testing, so YMMV.
The size impact compared to the master is: