4 ms·
I was about to say "well, it's probably a lot of work to verify that s isn't already a mangled variable name" but then I realized that doing what you suggested
by vanderZwan 7y ago
I was about to say "well, it's probably a lot of work to verify that s isn't already a mangled variable name" but then I realized that doing what you suggested in the pre-minified code should work, yeah.
So not only are you right, it's actually super easy. Just do this at the top level of your code:
const {cos, sin, PI /* etc */} = Math;
- KilledByAPixel 7y agoYou could do that, but it would not compress as well. For example the word const is not use anywhere in the 2k version, while Math. is used about 40 times so it becomes essentially free when compressed.
- vanderZwan 7y ago> For example the word const is not use anywhere in the 2k version, while Math. is used about 40 times so it becomes essentially free when compressed. Except that the word const does seem to be used in the uncompressed version, so we don't know what happens during compression in the Closure compiler, no? Or is the 2k version pre-Closure compiler different from the uncompressed version? Either way the only way to know is to try because asymptotically free is all well and good, but without measurement we don't know the actual behavior in practice and we are just making assumptions about how well or how badly things compress and how the mangling process works out.
- KilledByAPixel 7y agoOk, I just tried it. Removing every Math. and adding let{cos,sin,PI,min,max,tan,atan2,abs,ceil}=Math; to the top. It worked better then I expected, though it is still 1 byte larger then without. Could potentially be a win in some situations.
- vanderZwan 7y agoNice! Thanks for trying! > it is still 1 byte larger then without That's actually pretty cool, because together with your earlier remark of ~40x occurrences of Math.<whatever> that means we have a ballpark figure for where the tipping point is!
- deleted 7y ago[deleted]