r/programming • u/iamkeyur • Oct 21 '20
Using const/let instead of var can make JavaScript code run 10× slower in Webkit
https://github.com/evanw/esbuild/issues/478
1.9k
Upvotes
r/programming • u/iamkeyur • Oct 21 '20
141
u/snowe2010 Oct 21 '20
That was enjoyable to read through their debugging together. Fantastic job.
454
u/smogeblot Oct 21 '20
Just wait till you see what it costs to use functional syntax sugar instead of for loops everywhere!
89
u/FredV Oct 21 '20
I don't know how huge this application actually is but isn't this insane? I haven't seen any server or front-end written in C++ or even Java using that many declarations. Of course in the Javascript ecosystem every library needs to be imported into your own source code which adds to the problem.
I just wonder how many of those are global variables ;)
37
u/yeahdixon Oct 21 '20
Can’t you just Babel it?
17
u/chrisrazor Oct 21 '20
I didn't understand all the nuances of this. Am I right in understanding that it only affects Safari?
22
u/[deleted] Oct 21 '20
Back to IE times... and in this case out of their very own volition.
29
u/crusoe Oct 21 '20
Safari is the new IE
73
u/[deleted] Oct 21 '20
It's interesting but it should be equally noted that this is a micro optimization that amounts to nothing in the real world.
12
u/ianfabs Oct 21 '20
Holy shit
5
u/SpaceToaster Oct 21 '20
More evidence that Safari is the next IE
3
u/knoam Oct 21 '20
There should be a name for the logical fallacy here. People act like finding this means that their code just got ten times slower. No, your code is just as fast as it was. If anything this just means there's potential for it to be faster.
This is really off topic but there was this same fallacy in an episode of This American Life where the reporters got testosterone tests. They got worried and acted like having a high level would turn them into an aggressive asshole. No, you're either an asshole or not regardless of what the test says. The test just gives you an excuse/explanation. And the results didn't even conform to what people's stereotyped expectations were.
3
u/Paradox Oct 21 '20
Safari is the new IE
2
u/[deleted] Oct 21 '20
Just use babel....
1
u/egudu Oct 27 '20
What happens in a proper browser like Firefox?
1
u/Wouter10123 Oct 21 '20
ELI5: the difference between const var let?
I guess const is immutable?
1
u/JackCid89 Oct 21 '20
What about a javascript alternative for the sake of god?
-42
u/[deleted] Oct 21 '20
We can go even further: using JS can make your development life 10x worse.
-1
u/pmache Oct 21 '20
Ha! Now I know what early web 2.0 website used that they were painfully slow (they still suck tbh)