anyone ever told you "premature optimization is the root of all evil"?

let me tell you a story. about computers and javascript and hitler and the soviet union.

a friend of mine just dug up some numbers and did some math for my dyscalculic ass and came up with the conclusion that just by transmitting the minified version of jquery around (not even executing it!), Planet Earth is likely using up somewhere between 7-14 billion kWh of power every year.

let's put that into some perspective.

world war two was the single deadliest conflict in human history. it killed somewhere around 80 million people, which at the time was three percent of *all humans, everywhere.* it left europe in ruins, and nowhere was the damage so intense and horrific as the Soviet Union.

the Battle of Stalingrad is one of the most famous battles of the war. two million people died there alone. in the opening salvos the entire city was flattened by nazi and soviet bombs alike. eventually the Union prevailed, at a tremendous cost.

but Stalingrad was only one of the cities flattened, only one of the battles fought as Europe burned. the devastation was so comprehensive that nearly every western nation had to rely on aid from the US, one of the only powers on either side whose economy was intact, to rebuild. (it didn't help that American wartime policy was designed more to inflict as much Nazi death and destruction as possible on the Soviets, of course).

if we add up the energy of every single explosive device detonated over the course of that terrible war, from hand grenades all the way up to the two atom bombs the US detonated over japan, slaughtering civilians en masse and turning two cities to rubble in the space of a moment, we get the figure of about 3 megatons. or in kilowatt hours, 3.4 billion, spread out across all those years of war.

compared to 7-14 billion kWh just to transmitting the same tangle of bytes around again and again. every single year.

and that's just jquery. not the cost of executing it. not the mass of other garbage javascript and analytics and social media spyware, which now often adds up to megabytes per page. not the cost of rendering or running any of that.

just to zap jquery back and forth across the internet to every computer accessing a website that uses it.

a final point of comparison, now that i have your attention: bitcoin uses up 46,000 billion kilowatt hours per year. a number which is likely to keep on growing.

draw your own conclusions about web design & software optimization.

@velartrill I just woke up, so perhaps my brain isn't QUITE functional, but -

exactly WHAT does sending bytes around have to do with premature optimization?

Your story compares compression - which minimizing javascript is a BIZZARRE form of (gzip delivery is actual compression; minimizing is more "There are ways we can transmit less." Gzip delivery can then reduce a few bytes more.)

Premature optimization is an _anti-pattern_ developers should avoid EXCEPT in rare cases.

@velartrill I ABSOLUTELY agree that compression of bytes saves energy. As does writing code that is efficient. Spending some time assuring that your code does not waste energy - or using the right tool for the job, rather than just the one you have - that also can save energy. Saving energy is a _good_ practice.

If your comment was intended to say that optimizing code can reduce energy, and therefore this is good: then I didn't find that before writing this 2nd statement.

@velartrill An example of wasted energy caused by code that should NEVER have been deployed to production:

SQL query run to match 2 lists; but first list had no integer identifier, and it's primary key was the email field.


This simple query would take over 24 hours and, as it could not be fixed without affecting customers, required adding 8 processors and 24 gigs of memory to just get it to run in 24 hours.

Fixed query: 2 minutes. 128megs. 1 cpu.

@velartrill Had someone pointed out to this developer (and management) that this query was WOEFULLY inadequate, and the reason why, he'd have fixed it. And every time he writes a query now, or designs a database, he checks that he is using best practices.

That's not premature optimization.

That's doing your job well, and saving energy.

(This story can be modified for those who put money before energy by talking about the COST of energy wasted. Sometimes that change is needed.)

@Shamar @velartrill also if you happen to run into any nice, _working_ minimal browsers (that don't insist on using _ONLY_ vi keys, or can be easily altered to do basic things with other keys for navigation) then let me know.

surf is... not really working that well these days; netsurf has http2 issues; midori ... crashes...
and I don't have time to go fix them ):

@velartrill @Truck @alcinnz

I also like because it's written in plain and thus pretty portable. The codebase seems pretty readable and well organised too, so it could be another good choice if you want to learn about the internal of a browser and hack something like that.
The problem I see with Netsurf is that it aim to implement the standard, while the standard are designed to keep all 's competitors out (see end of life).

Sign in to participate in the conversation

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!