3 ms·
v8 at one point made inlining decisions based on character count. Terse code would be inclined more aggressively, and even adding comments could defeat inlining
by ridiculous_fish 9y ago
v8 at one point made inlining decisions based on character count. Terse code would be inclined more aggressively, and even adding comments could defeat inlining: https://top.fse.guru/nodejs-a-quick-optimization-advice-7353b820c92e https://top.fse.guru/nodejs-a-quick-optimization-advice-7353...
- notamy 9y agoI can maybe understand why v8 would do that, but why on earth would comments be included in that?
- maccard 9y agoBecause its faster to get the length of the string before you strip out the comments I guess?
- spoiler 9y agoIt's because back then V8 didn't save the AST in `SharedFunctionInfo`, so AST was inaccessible, so to avoid re-parsing and generating the AST to use AST-specific heuristics for inlining big function bodies, it used just the source length as part of the inlining strategy. This has been fixed for a while now with TurboFan[0] (also, now you can call `ast_node_count()` and get the AST count directly). [0]: https://github.com/v8/v8/wiki/TurboFan https://github.com/v8/v8/wiki/TurboFan EDIT: added information about `ast_node_count()`