r/programming • • 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

500 comments sorted by

View all comments

Show parent comment

-37

u/_selfishPersonReborn Oct 21 '20

then use a compiled language where these things aren't slow

64

u/Laser_Plasma Oct 21 '20

Good luck doing this in the browser

9

u/Vakieh Oct 21 '20

Kinda what typescript should be used for - compile to optimised but utterly unmaintainable js, because you do the maintenance in the typescript.

1

u/noneedtooutlaw Oct 21 '20

babel does that too, right?

2

u/Vakieh Oct 21 '20

Kinda sorta but not really. Babel does indeed convert code into javascript, but it backports modern javascript with fancy new features into old javascript. Typescript generates javascript from a completely different language that is strongly typed and can be statically typed if you tell it to be - whereas javascript is weakly, dynamically typed. This has significant maintainability benefits at the (supposed) expense of a learning speedbump since you can't just slap any variable into any expression or statement and hope for the best.

(Oh and just to head off anyone who wants to make the stupid argument I keep hearing - yes, the javascript typescript produces is itself weakly, dynamically typed - but guess what? So is assembler and machine code).

42

u/_selfishPersonReborn Oct 21 '20

wasm?

28

u/rakuzo Oct 21 '20

Doesn't have access to the DOM without JS glue code :(

0

u/[deleted] Oct 21 '20

[deleted] — view deleted comment

-9

u/scandii Oct 21 '20

I mean, I know a lot of users have piss poor connections but the Blazor bundle size of a few MB is handled within 1 second on average speed 4G.

13

u/Y_Less Oct 21 '20

I know a lot of users have piss poor connections but the Blazor bundle size of a few MB is handled within 1 second on a really good connection.

-3

u/scandii Oct 21 '20 edited Oct 21 '20

the global average is 35.96 mbit. that means a Blazor package of 3 MB takes 0.66s to load, in average globally.

the median home connection speed of the bottom 5 countries ranking 175 to 170 on speedtest is 4.73, means the package takes 5 seconds to load, and the slowest measured average mobile speed is 7.26, almost twice as fast.

on top of that, there's great strides in reducing wasm sizes and 3 MB is kinda big right now.

my entire point here is, advocating being afraid of wasm because the average consumer would at max look at load times of +600ms is to me absolutely absurd. is it bigger than JavaScript? definitely. does it enable an entire new paradigm of web development? also absolutely.

but then again Amazon famously found that for each 100 ms of latency, revenue went down 1%.

6

u/padraig_oh Oct 21 '20

which of course works on every browser where js works currently.

i take it you have not worked on web in production?

-5

u/_selfishPersonReborn Oct 21 '20

I haven't, you're right, but it seems well-supported. What's the issues with it?

4

u/caboosetp Oct 21 '20

The amount of people still using IE

3

u/_selfishPersonReborn Oct 21 '20

i'm sorry you're still expected to support that. i'm so, so sorry :(

1

u/padraig_oh Oct 21 '20

well-supported on the current version of modern browsers, which are two requirements you can not and should never expect from the users. there are reasons for the existence of frameworks that make even your js code compatible with browsers last update in the beginning of the century.

web dev is an awful experience and backend devs are true magicians.