4 ms·
I can maybe understand why v8 would do that, but why on earth would comments be included in that?
by notamy 9y ago
I 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()`