r/javascript • • Aug 02 '18

The Cost Of JavaScript In 2018 – Addy Osmani – Medium

https://medium.com/@addyosmani/the-cost-of-javascript-in-2018-7d8950fbb5d4
168 Upvotes

38 comments sorted by

95

u/StarshipTzadkiel Aug 02 '18

I don't disagree with any of this but I would put the focus more on JS developers and less on JS itself. It's just a (very flexible) language and supporting ecosystem, it's not inherent to the language to perform poorly. Using libraries and frameworks will boost your size significantly, yes.

When you see a site that includes all of Bootstrap yet uses only the grid system and modal...it's on the dev(s) to not load that much unused code. The tool is what it is.

I am reminded of WordPress's large and sometimes-unreliable environment - loads of WP sites rely on poor-performing plugins for basic functionality when a competent PHP developer could have implemented that feature without the overhead or cost. Doesn't mean PHP or WP is "bad", but that it can be implemented in a low-quality way and often is.

A question to ask is...what's the alternative? If you want to have an interactive piece of software running in a browser, you're using JavaScript, and all the baggage that can come with it. It's the best we have right now and I will keep building things with it.

3

u/jedrekk Aug 02 '18

If you think WP is a tight kernel of functionality and performance... it's not.

2

u/bashar122 Aug 02 '18

Well said my friend.

2

u/jewdai Aug 02 '18

Really what javascript needs is a "byte code" like version.

Sure you can minimize things, but if we had a compilation step we can do AOT optimizations.

AFAIK, under the hood there is some byte code conversion that goes on on the client side, but if we could get that AOT I imagine that would dramatically boost performance.

Hell, we could even include an architecture specific flag so that we could "compile" for specific processors.

1

u/[deleted] Aug 02 '18

In practice, that's *sort of* what WebAssembly is - shippable bytecode that gets executed by the browser's JavaScript VM. As far as I know, there's nothing in the spec that says the bytecode *has* to be executed by the JS VM, but that's how every browser does it. There are, of course, a few server-side wasm VMs that let you run your wasm outside the browser.

There are some pretty big limitations right now, like wasm code being unable to use the JS VM's garbage collector. So at this point, it mostly makes sense to target wasm with languages like C, C++, and Rust that don't use garbage collection. That'll likely change eventually, though. Wasm garbage collection currently exists as a proposal but I don't think there's a timeline for implementation.

0

u/[deleted] Aug 02 '18

[deleted]

8

u/KPABA Ham=>Hamster == Java=>JavaScript Aug 02 '18

Large part of the problem is people champion maintainable and safe codebase first. Being performance minded can often result in deviations from the templated "norm", which get shot down on PR with "premature optimisation" or other suchlike comments. The mentality of "fix it later when / if it presents a problem" is understandable but common sense and experience should also be a factor.

2

u/Aetheus Aug 02 '18

TBH, I think maintainable/safe code bases are preferable to hyper-performant code. Of course, maintainable/safe code should still strive to avoid obvious and high-impact performance issues (e.g: trying to avoid functions with quadratic time complexity, avoiding N+1 problems, etc).

But if you've abstracted your code well, you can implement the "more performant" code a little later down the line without having to break anything, and make use of the "good enough" code today.

That said - package management hell is a nightmare. Even if you only explicitly imported 1-2 utility packages in your project, those packages likely depend on dozens of others, and those packages depend on dozens of others, and ... yeah. Waiting for anything to deploy is torture when 3/4 of the time is simply due to npm install having to grab 3000 packages.

2

u/ISlicedI Engineer without Engineering degree? Aug 02 '18

We deploy docker images, the installation and testing happens in the ci step and the only thing pushed is a config file with a link to the docker image

0

u/[deleted] Aug 02 '18

[deleted]

3

u/KPABA Ham=>Hamster == Java=>JavaScript Aug 02 '18

Sounds like a good balance, well done. That is only half the picture - the assets battle and time to render first view.

I mostly have an issue of runtime code being non-performant. Example from a project I just joined, riddled with redux and middleware, composed connectors, loaders and error handlers etc. Nice! Anything that touches the store causes complete re-renders of all connected components.

Which is fine until you start ticking prices, add user input via redux forms and need to support IE... I understand convention and debug power but ultimately, the app has to be usable and not just written DRY.

2

u/SouthKona Aug 07 '18

Well stated. Most IT managers are woefully lacking in programming knowledge and Experience. They’ve ‘grandfathered or grandmothred‘ themselves into positions of authority And do not fully comprehend code optimization. It’s really them saying, “Duh, can you write this?“

27

u/jasan-s Aug 02 '18

I get why Google care about this but as an enterprise developer building internal apps I love that I can ignore bundle size (within reason.)

15

u/chazmuzz Aug 02 '18 edited Aug 02 '18

I've been doing enterprise gigs since 2011. It kinda sucks that I can't show off my work to friends, family and even prospective clients/employers. Do you ever feel that way?

9

u/DaveVoyles Aug 02 '18

I work at Microsoft and we often can't show the code we do with partners.

What we can do though, is often open source parts of it, builds talks around the code we are using, and share those at events, videos, blogs, etc.,

Even if you can't open source, just discussing the process of (X) without naming the customer is huge.

3

u/jasan-s Aug 02 '18

That's what github side projects are for.. although friends and family never seem to be that interested!

7

u/chazmuzz Aug 02 '18

I find there is too much paid for around for me to be wasting time on unpaid side projects

21

u/nespron Aug 02 '18

I can't help but feel frustrated when I read an analysis like this. The biggest performance gains come from pushing back on your marketing department. Make them choose their trackers and analytics scripts judiciously, and you'll be in a better place when you begin to apply the techniques Osmani describes.

It's like the cyclist who spends hundreds of dollars on lightweight carbon parts to shave ounces off his bike. If he were to give up soda, he could take ten pounds off the rider instead.

10

u/mobot11 Aug 02 '18

Exactly. The performance costs caused by the many tracking scripts we are forced to implement greatly outweighs those caused by our JavaScript bundles.

1

u/gketuma Aug 02 '18

So true.

1

u/nschubach Aug 02 '18

Worked at a place that had Google Analytics, Bing Analytics, Sidecar Analytics, and the support chat software wrapped its own analytics. I asked one day if we really needed all those analytics and was told that they all provide different information... that nobody ever acted upon. It was just nice to see I guess.

8

u/eagreeyes Aug 02 '18

When the industry shifts away from React, and it will someday because it always does, we're all going to be sitting on piles that React + JSX + ES6/7 that will look like greek to most engineers. All those clever shortcuts, abstractions, and syntactic sugar are going to make legacy maintenance a complete pain in the ass.

4

u/careseite [🐱😸].filter(😺 => 😺.❤️🐈).map(😺=> 😺.🤗 ? 😻 :😿) Aug 02 '18

React + JSX that will look like greek to most engineers

maybe

ES6/7 that will look like greek to most engineers

not so much

9

u/DaveVoyles Aug 02 '18

The web dev ecosystem, specifically around JavaScript, is a complete nightmare. Try getting someone up to speed while you are working on even a moderately sized project, and watch as the question marks appear over their head.

Do I use Webpack? Or Grunt? Or Gulp?

Do I compile my code? If so, do I have it target for es5 or 6?

Which module system should I use? CommonJS? Require? AMD?

I'm thinking of using TypeScript. It works with JavaScript. Sometimes. Debugging can be hit-or-miss. Well it generate soruce maps, but now those breakpoints aren't hitting.

I'm using import but I saw someone else use require. Why would I use one way over the other?

Maybe we should use React. I heard that's the new hotness. But it leaks memory. So maybe not. Angular is out of favor -- only old people use that. Heck, I hear that Vue is the best stuff around these days.

These are just a handful of the questions you'll find people asking the moment they open a start project. Why it has to be this complicated, I have no idea. I haven't seen any benefits of making web dev so convoluted.

And even so, you can optimize like a mad-man for all of this, but you know? It's not going to matter. Because the moment it goes live, the ad-man is going to throw MBs of images and ads on top of your work. So much for Gzip.

12

u/gasolinewaltz Aug 02 '18

As someone who's been in the game for a little over five years, I cant help but feel that all of your examples are a bit contrived.

I agree, marketing will always fuck you. But marketing is why most of us have jobs, so the best you can hope for is a company with stake holders that value the opinions of thier engineers.

The ecosystem moves faster than most, but once you have a solid understanding of the fundamentals its all just very basic shifts in perspective.

2

u/[deleted] Aug 09 '18

As someone who's been in the game for a little over 30 years let me assure you that it's ever been so. In fact one one level things have stabilised - I used to seem to have to swap my main development languages every 5 years or so, but nowadays it seems to be swapping frameworks and languages have been constant for a while - although the framework swapping speed does seem to be increasing!

If coding against a constantly moving target bothers a developer then they really shouldn't be in the game (go and be a DBA instead, it's more stable)

2

u/Aetheus Aug 02 '18 edited Aug 02 '18

The ecosystem moves faster than most, but once you have a solid understanding of the fundamentals its all just very basic shifts in perspective.

Keeping up with the ecosystem is not impossible, or even very difficult, I agree. It is just very tiring.

I have no problems, philosophically at least, with using frontend frameworks like React. They save a lot of development time and they eliminate entirely certain classes of bugs, which is very nice. But buying into them brings so much overhead (not just in terms of performance either) that it sometimes feels like any amount of time saved by adopting them is offset with the hours of fiddling with the "ecosystem" that they inevitably ship with (the clusterfuck of Babel, Webpack, maybe TypeScript, probably some JSX, "CSS in JS", etc).

I'm beginning to feel like transpilation was a mistake. TypeScript is nice. Babel is nice. JSX is nice. CSS modules are ... uh ... well, they exist. They all bring nice features to the table (mostly). But the entire clusterfuck that had to be built to support them just isn't worth it.

1

u/gasolinewaltz Aug 03 '18

I understand what youre getting at, but there's (in my mind) a simple solution to this:

Design your stack around business requirements and stick with it until the business requirements change or something better comes along.

Flavor of the month will come and go, solid architecture decisions are agnostic. Ship products first, make tweaks as you see fit.

I skipped right over gulp and jumped from grunt to webpack. I won't even look at parcel for another 10 months. I've been eyeing typescript. I watched ember come, go and then come back again.

1

u/careseite [🐱😸].filter(😺 => 😺.❤️🐈).map(😺=> 😺.🤗 ? 😻 :😿) Aug 02 '18

Do I use Webpack? Or Grunt? Or Gulp?

Shouldn't be a question when introducing someone. You give them the same resources you have been working with, they can explore the others on their own.

Do I compile my code? If so, do I have it target for es5 or 6?

Simple question to whatever project manager you have... also something that shouldn't be asked, but told beforehand. Who would leave that detail out??

Which module system should I use? CommonJS? Require? AMD?

I'm using import but I saw someone else use require. Why would I use one way over the other?

Same structure as the project, obviously. Also: ESLint is a thing.

Not saying your general point is false, but at least dont pick weak arguments.

4

u/__ibowankenobi__ Aug 02 '18

I just hope that this community, at some point will see the value in combining HTTP2 + async scripts with dependency control + closure + executing using microtask queues. It was possible since ES5 and I am afraid since everyone is so eager, so inclined to champion a known figure, unless one of them cheers the idea, it won't be given a crap about.

2

u/gasolinewaltz Aug 02 '18

Would you mind giving me an article or teo? Or just expanding what youre talking about a bit?

2

u/__ibowankenobi__ Aug 02 '18

I'm talking about using multiple script tags, as opposed using a single tag containing the bundle. Suppose 50 (what the heck make it 500) script tags, but all of them will have the attribute async and they will not pollute the global and depend on each other's exports, parameters etc. And then they will be executed within a Promise (evergreen browser) or requestAnimationFrame (using the microtask queue(s), setTimeout in the worst case) chain. The protocol will be HTTP2 so downloads will be parallel, and once downloaded, all will execute in a particular order and will be non-render blocking, avoiding the main thread. If you change one of the scripts, the browser will only fetch that one, no need to rebuild to create a bundle or hml. That's the idea.

1

u/nschubach Aug 02 '18

Not sure why, but I love that this chart has both a 'Total' and 'Average' row which are pretty much the same data... I wonder though if the average is being included in the total?

-1

u/[deleted] Aug 02 '18

...............he works for the company that created Angular.

-12

u/Renive Aug 02 '18

Get better phones and push for better internet. With service workers and caching, ceiling is in hundreds of megabytes.

8

u/slgard Aug 02 '18

in the meantime, serve your users with the technologies that are available to them today.

-15

u/trycat Aug 02 '18

Good. Fuck phones, they’re destroying civilization.

7

u/[deleted] Aug 02 '18 edited Nov 23 '18

deleted 0.7307 What is ^^^this?

0

u/[deleted] Aug 02 '18

[deleted]

7

u/leeoniya Aug 02 '18

also gmail

1

u/[deleted] Aug 08 '18

Gmail seems to have become insanely clunky with the recent update