DEV Community

Cover image for Maximum JavaScript Performance

Maximum JavaScript Performance

K on April 01, 2018

Cover image by Fachstelle für Öffentliche Bibliotheken NRW on Flickr. If you're a bit like me you probably think a lot about how to make your soft...
Collapse
 
ben profile image
Ben Halpern

Collapse
 
damcosset profile image
Damien Cosset

Holy fuck, it took me way too long to realize this was a joke :D

Well done, sir!

Collapse
 
joelnet profile image
JavaScript Joel

slow clap

Collapse
 
pmcgowan profile image
p-mcgowan • Edited

I went through the first first one thinking I'm not so sure about that, does it really increase performance though? Got to the second one and thought I guess this makes sense, but readability-wise no... "no more than two letters"... ohhh, I see what's going on here.

Collapse
 
phpfour profile image
Mohammad Emran Hasan

This will start popping up in search results given the organic boost of dev.to and a lot of newbies will NOT know this was a joke...not everybody reads the conclusion! You might want to consider changing the post title sometime in the future.

Collapse
 
kodikos profile image
Jodi Winters

Reading this in mid-August meant I didn't realize it was an April fool - I certainly wasn't fooled that these were performance improvements. Instead, it read to me like a snarky jibe aimed at those seasoned ex-perl devs and the like who had some very bad habits. Those habits happened to serve fairly well as a way of keeping one's job.

Collapse
 
kayis profile image
K • Edited

Haha, interesting interpretation :D

I never used Perl, I just read once that it was the reason PHP was invented and if you had to invent PHP to solve something, things probably went awry XD

Collapse
 
kodikos profile image
Jodi Winters

Just so I don't get flamed, I did say "perl and the like"! PHP started life as 2 perl scripts designed to make perl easy to use to create web pages, from there it exploded into the most popular web programming language for a good 10 years.. can't have been that bad! PHP4 did have some crazy performance hacks that made it run faster, like not splitting your classes into separate files, just one long huge file made a super difference to performance!

Thread Thread
 
kayis profile image
K

Just was making fun here :)

I started my career with PHP and was a PHP developer for 5 years or so.

Collapse
 
ackvf profile image
Vítězslav Ackermann Ferko • Edited

I did laugh hard over your suggestions, but I just had to try number 4 in console, what a hilarious way to code! x'D

loop took 1,7 ms
fastloop tok 27 ms

Now I understand that you tried to go from simple to complex ideas, but variable names really ring a bell that this is a joke - maybe little too early.

Collapse
 
lluismf profile image
Lluís Josep Martínez

Translate to spanish and post it december 28th.

Collapse
 
kenakamu profile image
Kenichiro Nakamura • Edited

Great article K! Any downside of each code you introduced? By the way, you post is appeared on April 2nd in Japan :). So you should be serious!

Collapse
 
dgubert profile image
Douglas Gubert • Edited

I was reasoning about how deferring things to the event loop like that would make things better when I realized the date this article was published xD

And, tbh, I only started really doubting things when I got to the with section :P

Collapse
 
henryjw profile image
Henry Williams

Thanks for sharing. I've noticed a 3x performance gain after implementing these changes!

Collapse
 
kayis profile image
K

Next: Delete system32

Collapse
 
efleurine profile image
Emmanuel

A lovely one

Collapse
 
ptmaroct profile image
Anuj Sharma

You monster

Collapse
 
yujinyuz profile image
Yujin

I just realized this was a joke after seeing:

// instead of
myRandomNumber = Math.random();

// write
r = 17;

Collapse
 
avalander profile image
Avalander • Edited

Hilarious!

The well kept performance secrets senior JS devs hiding from you <- This should have been the title.

Collapse
 
alijawad987 profile image
Ali Ibrahim Jawad

I think my head melted reading those "performance tips". Then I read the conclusion section and facepalm'd myself. Good one!

Collapse
 
kayis profile image
K

Nothing like a good old trolling on the Interwebz

Collapse
 
reisclef profile image
Richard C

I had to scroll back up to check the date about half way down by setTimeout. I had my doubts for the first few but that one was just too much! Hehe.

Collapse
 
falansari profile image
Ash

lol I got what's going on after reading the 2nd x'D well done! I just hope some noob won't take it literally....

Collapse
 
brianaruff profile image
Brian Ruff

Kne it as soon as I saw global variables lol.

Collapse
 
gab profile image
Gabriel Magalhães dos Santos

never trust

Collapse
 
carloslfu profile image
Carlos Galarza

Nice post! I think everyone that cares about performance should write entire webapps in pure WebAssembly like old school people 💪💪💪.

Collapse
 
qm3ster profile image
Mihail Malo • Edited

The example in #3 is an actual improvement🤷

Collapse
 
alvinmilton profile image
Alvin Milton

As I read it, I found myself getting quite angry. Thank you.

Collapse
 
denji profile image
Denis Denisov
  1. Don't use functions = github.com/facebook/prepack
Collapse
 
ggalihpp profile image
Galih Pratama P.

But no 5 is legit isn't it? or is there any disadvantage of using with(object)? other than scoping.