

When comments slow your JavaScript code (70% slower with long inner comments) - zallek
http://jsperf.com/js-inline-cache

======
mraleph
For context, this is
[https://code.google.com/p/v8/issues/detail?id=3354](https://code.google.com/p/v8/issues/detail?id=3354)

JSPerf test case has misleading name: it has nothing to do with inline
_caching_ , but it is indeed related to _inlining heuristics_. V8 uses source
size in heuristics for historical reasons and source size includes comments
(see the issue above for more info).

Saying that comments slow down your code by 70% is an exaggeration: if you
remove all comments from your code it is unlikely that you will get 70%
speedup across the board on V8, though potentially you might get some. Test
case is really written in a way that highlights the issue, because loop itself
is tight, it's doing nothing but a monomorphic function call and target
function also is doing mostly nothing - this makes inlining of the callee
essential for peak performance here. It is unlikely however that your code
contains a lot of loops like this.

~~~
zallek
"It is unlikely however that your code contains a lot of loops like this."

Absolutely agree.

------
danpeddle
Ran the same test in node 0.10.33, and despite also using V8, does not have
this behaviour.

[https://gist.github.com/dazld/2a5dc58f5c9ce61bccae](https://gist.github.com/dazld/2a5dc58f5c9ce61bccae)

Was about to start minifying all the server code too.. ;)

~~~
mraleph
Add 2 more characters in f3 (e.g. two empty spaces in the before return).
Right now the way it's written it's still below the limit.

That however does _not_ mean you need have to minify your server code.

Please don't base such decisions on some random microbenchmarks that have 0
connection to the code that you are really running in production.

Instead base these decisions on profiling of your actual application.

As I already said below: it is unlikely you get 70% improvement by removing
all the comments in your code. For that you need an app that does nothing but
a very hot tight loop calling the same small function that does almost nothing
too.

~~~
danpeddle
Absolutely agree - was just being a little facetious. Clearly not about to
start uglifying everything running on the server just because of a random
benchmark of unrepresentative functions running in a loop.

Correct to point this out, especially considering the predilection of devs to
micro-optimise based on the most spurious of hypotheses. Putting a single IO
operation in that loop will most likely completely change the picture, anyway
- although have not run the test to check.

------
sehr
Does anybody actually leave comments in their prod code these days?

~~~
zallek
People shouldn't, thought some still do particulary on server side

