4 ms·
V8 uses a function's length in characters, _including comments_, to make optimization decisions. By removing comments and shortening var identifiers internal t
by nteon 11y ago
V8 uses a function's length in characters, _including comments_, to make optimization decisions. By removing comments and shortening var identifiers internal to a function, I can imagine a number of functions dropping under that 600-char threshold. Would be great to measure.
- 0942v8653 11y agoSomeone in the last thread mentioned that you can actually configure this limit. So it may be slightly more accurate in the ratio when minified but probably not worth it.
- the8472 11y agothat seems like a terrible way to measure things. why not go by the number of some form of nodes after parsing? Parsing has to happen before optimization anyway.
- gmac 11y agoAgreed, this is awful. Presumably it means that adding comments can slow your code down, which I would otherwise have thought a completely laughable suggestion.
- laumars 11y agoThe problem with JIT compiled languages is compilation time is as critical as the performance of the compiled code. Using string length happens to be quicker than producing ASTs. So while it is a dirty hack, it generally offers greater performance more often than not.
- striking 11y agoNope. Parsing happens inline with execution, unless the function has less than 600 characters, where it'll be compiled down instantly. If it has any hotspots after that, they'll be JIT optimized. It is a terrible way, but you can't complain that it's a lot faster than rewriting V8 to count nodes.