5 ms·
> For parsing desktop facebook.com, 10-15% of client-side CPU time is spent parsing JavaScript. The prototype we implemented reduced time to build the AST by 70
by twii 9y ago
> For parsing desktop facebook.com, 10-15% of client-side CPU time is spent parsing JavaScript. The prototype we implemented reduced time to build the AST by 70-90%.
Whatever the win from their prototype, it should never be a reason to change core Javascript like .toString(). A facebook representative in this little proposal club doesn't feel good. My first thought was: please optimise your own codebase and don't break other people's code for your own profit.
- Yoric 9y agoOut of curiosity: do you actually use `Function.prototype.toString()`? I haven't seen any use of this method in years. Plus the few uses that I have seen were libraries that attempted to rewrite other libraries and broke at pretty much each update of their dependencies. There may be legitimate uses of this method in production code, but I can't think of any from the top of my mind. If you can think of one, don't hesitate to file it as an issue in the linked tracker.
- amptorn 9y ago`Function.prototype.toString()` is the basis for an alternate, ES5-era multiline string syntax: var str = (function(){/* STRING GOES HERE */}).toString().slice(14, -3);
- Yoric 9y agoThat's... an interesting use. I'm pretty sure it violates the actual specifications of JavaScript, breaks in presence of a minifier/uglifier and slows down your script, but it's a cool hack :)
- TheAceOfHearts 9y agoPrior to ES2015, the spec's definition of Function.prototype.toString() was pretty vague. The behavior was implementation-dependent, although I don't know the differences per browsers, since I've never used this feature seriously. Here's the text from ES5.1 [0]: > An implementation-dependent representation of the function is returned. This representation has the syntax of a FunctionDeclaration. Note in particular that the use and placement of white space, line terminators, and semicolons within the representation String is implementation-dependent. [0] http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.4.2 http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.4.2
- yorwba 9y ago> don't break other people's code for your own profit. How is adding a new kind of function (created from the AST encoding instead of source) with it's own definition of .toString() going to break other people's code? If you don't use binary ASTs you will never even see the new behavior. Unless you are the one mucking around with other people's code, in which case >> Function.prototype.toString.toString() "function toString() { [native code] }" Function.protoype.toString is already broken for functions without available source.
- codedokode 9y agoBreaking Function.prototype.toString() might actually be a good idea because now the engine has to keep the source code in memory and most of the times it is absolutely unnecessary. It would be better to free this memory.