Sayonara, V8
groups.google.com
groups.google.com
They barely document their engine internals or debugging tools, things change randomly making the existing documentation incorrect, and they frequently break the user-facing development tools like Chrome's JS debugger.
The only good things I can really say are that when V8 works, it works marvelously, and that if you can somehow track down a V8 developer they're usually incredibly helpful. Regardless, having to head over to the Google campus and buy a dev coffee isn't a scalable solution to these kinds of problems.
I've basically given up on delivering good performance in V8 as a result. The cost is too high. If I see obvious bottlenecks in their profiler (when it works at all), I tune them, but that's about it. I wasted a handful of weeks digging around in debug builds looking at bailout log entries and trying to decipher their IR using the broken log viewer they recommend, and the net result was that my code ended up faster for a few weeks until V8 changed again. Not worth it.
P.S. When I say 'anti-documentation culture', I mean it. V8 devs have personally told me they dislike documenting certain aspects of V8 and its internals because they fear that end-users and developers will rely on those internals. They lean towards occasional blog posts and Google IO presentation videos to pick up the slack.
Keeping up-to date documentation of compiler is a horrible job. I think it's good enough that V8 may be built as standalone binary with really extraordinary debug options and tools.
At the same time, I'd love to see more talks like http://www.youtube.com/watch?v=FrufJFBSoQY There are also guys who write about V8 from time to time (http://mrale.ph/ http://floitsch.blogspot.com/ http://wingolog.org/tags/v8) but this is needle-in-a-haystack type of learning.
The same dislike of documenting performance details and internals exists on the SM team, though.
Standalone binaries with debug options like d8 and spidermonkey js.exe are great for narrowly-scoped tuning and microbenchmarks, but in the real world your app runs in the browser and you end up having to debug and profile it there. That's where the whole picture falls apart (and where Spidermonkey's tools are dramatically better).
Mozilla ships two different performance analysis tools for in-browser JS that give you extremely detailed, precise performance information (JIT Inspector and SPS). They're more stable than Chrome's tools on average as well. You can literally get the browser to dump the native assembly it produced when JITting a given function.
I haven't done any perf tuning in a while, so this page is probably out of date, but I've made a point of documenting the stuff I discover about each engine, and linking to sources where possible: https://github.com/sq/JSIL/wiki/JavaScript-Performance-For-M...
You can literally get Chrome to dump native assembly it produces when JITting a given function. You just need to build Chromium yourself, because disassembler is not built into it. It's a dead bloat I guess for 99% of people, even for JS VM engineer disassembly is the last resort. You can get compiler IR from any Chrome build and people do get it. And usually it means that VM itself should be fixed.
People should not need to care about IR or (worse) disassembly. If your code is reasonable it should just work reasonably fast. File bugs if it does not, instead of tuning, which can break as soon as V8 moves left or right.
I agree that in general users should not need to care about IR or disassembly. Unfortunately, I'm not sure we'll ever end up in that world.
IIRC V8 has Debug.disassemble(f), requires both a special build and mirror debugger exposed to the page. Prints disassembly to stdout. Can be tweaked to return disassembly as string, but that requires knowledge of V8. (I actually don't know who is the client of this function or why it was added).
[side note: if you get function disassembly you can't really be completely sure that that's the code that was running 2 seconds ago, that's one of the reasons why V8 just dumps everything]
I was trying to get disassembly of asm.js compiled by IonMonkey a couple of months ago. I had to run SpiderMonkey under gdb and disassemble the JITted entry points. (Or maybe I didn't...)
I don't know if this dumps the disassembly for asm.js. I suspect it can't, since asm.js modules are AOT compiled into a single big block of code - but maybe it'll work. Give it a try!
The trouble with this is that the results are not in your own hands. Developers have bosses and deadlines and all that, and when it comes down to it, they just need to make it work. In that position, it's awfully hard to "submit a bug report and pray," and though it's not optimal, the ability to get into the guts of things can satisfy the immediate need.
You don't need to be praying. If no immediate fix can be made in the V8, you will get some recommendations and explanations based on the V8 team knowledge.
I would go as far as saying that bug reports like this are a single most reliable signal of what JS developers want to be fast on the web. By not reporting performance issues and silently working around them you hinder this signal. THere might be bugs and inconsistencies in underlying VM optimizations that can go unnoticed for a long time due to that.
This doesn't strike me as too egregious, personally. I can understand library maintainers taking any steps necessary to prevent people from relying on fluid internals. If anything, this suggests (to me) that the interface might not be rich enough to accomplish what people want. But it isn't a sin to keep documentation of internals private.
Shamefully in this instance the problem is changes to the public embedders API... so we shouldn't rely on it? Why did they create the API?
I work on GWT. GWT has, since 2008 at least, relied on certain low level details of the NPAPI in browsers for implementing its Development Mode. Both Chrome and Firefox break this API consistently, in fact, Firefox breaks it on every single release. Eventually NPAPI will go away, because it was designed in a bygone era of Flash plugins.
Unfortunately, it's not being replaced with anything that solves our use case, nor does PPAPI solve it.
I really feel for the author of v8-juice, but it's more important that the browser vendors drive performance and security forward, and given how tightly integrated JS is with the browser, you would have to expect that radical design changes in internals are eventually going to break low level APIs, even if they are public.
I thought coffee was free over there ;)
I must say that public facing API is well documented right in the header files. Each class and majority of important functions have long comments[1]. So claiming that V8 has an anti-documenation culture is incorrect. Next I would like to note that V8 is surely open to patches that improve documentation of public V8 interfaces. I don't remember a lot of those patches flying in though.
Finally, documenting internals is completely different from documenting API. I don't think it is feasible to maintain such documentation. Internals exist only to rely on them in an extreme cases and in such extreme cases reaching to V8 developers directly or reading the source code is the only way to get correct and what is more important up to date information given how things are constantly in flux.
[1] https://code.google.com/p/v8/source/browse/trunk/include/v8....
It's bad enough as is with developers relying on undocumented behavior, see the troubles Wine (and Microsoft as well) with applications that touch Windows internals.
However, the discussion here is about side effects of the V8 implementation, as they relate to performance. That is to say, the V8 team is reluctant to do anything that suggests "if you write javascript using this pattern, your code will/will not run fast, but only because that's just how this week's code branch works out". If the team made those sorts of promises with a project as complex as V8, they effectively become locked in to their existing code, unable to change or improve much of anything because they'd be breaking the promises of performance patterns they previously issued.
The authors who are working with V8, on the other hand, require those promises to be made. It's not enough for the performance patterns to be documented, these authors need them to be fairly stable as well.
It's a tough situation - the V8 authors have made all the promises and documentation that's practical for them to do, but it's not enough to satisfy these other project authors' needs.
Its open source if you have access to the source, not because you can grok the code.
The internals of V8 ought to be undocumented, if it not intended to be an api that other systems interfaces with. Api behaviour should be documented, and i assume that's what the V8 team does - but the internal IR, for example, is private and its behaviour should not be relied up on, or do so at your own risk.
People keep going back to the point of private API docs - private details are private for a reason. Nobody but the v8 devs need private internal docs, and those MIGHT exist in encyclopedic form somewhere in Google. Those don't interest me. Public APIs are missing (or exceedingly poor, relative to v8's scope).
I would say that I am a bit torn on this issue.
First of all, I would love anybody using V8 to be able to troubleshoot issues they are running to as easily as possible. Ideally you should see your source annotated with optimization suggestions and internal V8 information translated into digestible form. I experimented with some ways of doing that but sadly I totally lack time to make a product out of that.
However I am not sure making some static cookbook of performance patterns is the right way to go here. It certainly can help in the short run, but in the long run its the uniformity of optimizations on V8 side and general shape of your code that matters. I fear cargo cult blindly following such a cook book without making an attempt to understand.
Additionally I fear that it is extremely hard to make and maintain such a cook book given that VMs consist of extremely many moving components and sometimes you can't decompose performance of an application into performance of small patterns, they interfere with each other. Understanding of internals, or understanding of how and where get the information on internals is much more important.
Maybe I am wrong, but I am doing my best to actually help people to become interested in V8 internals instead of following blindly recommendations.
[1] note: we are not talking about JavaScript debugger itself which should be relatively well documented as far as I understand, C++ header files look like they contain a lot of comments and I know there is a protocol description on the wiki.
Not really sure how we get out of the spot we're in, unfortunately - in practice JS optimization is a mix of black magic and cargo cult wisdom that can become outdated as engines improve, and I can see that causing a lot of long term drag on productivity as engine authors have to keep tuning their engines for bad code.
I hope you keep getting traction on exposing developers to V8 internals; the stuff I've learned about both V8 and spidermonkey internals has been very useful so far - my complaint is largely that the learning process is difficult, not that there's anything wrong with your codebase :) I love that so many of the v8 JS builtins are self-hosted in JS instead of C++ - makes it much easier to peek under the hood and figure out what they're doing!
http://fossil.wanderinghorse.net/repos/f2/doxygen/
it is experimental, alpha quality, and developed only by me. It has more public API docs than v8. i cannot for the life of me comprehend how, given the vast amount of Hacker Skill in the v8 team, so little documentation (often of useless quality) comes out of it. i don't have the headers with me now but the last time i looked at the docs for Context::EnterContext(), they said, "enters the context." No joke.
Not my problem, anymore.
You have the same problem with any other modern JavaScript VM. There is always lots of magic and some heuristics which can easily break. As a result, performance is hard to predict.
For what it's worth, Dart fixed that. Predictable performance was one of its main goals/constrains.
Stephens libraries aim to abstract this API into something more palatable (simpler marshalling back and forth, function signatures, object mapping etc), so clearly breaking changes to this API can result in huge rewrites, and the most recent changes are daunting. Disclaimer: I never used his libraries but was well aware of them.
Maintainer of v8-juice/cvv8: "Sayonara, V8"
Article is about V8-juice author abandoning his library for reasons that I don't personally consider right or wrong. I wanted to share this because there is a slight chance that state of V8 documentation (which I've never seen or used myself) is a political decision on a higher level (too little outcome from too much effort) and some discussion around the topic may change that.
Given Stephan's claim that the new version of v8 is incompatible with all applications, though, I suspect some energy will be expended to make node compatible. Node at least has a huge pool of users and developers to draw from when tackling a change like this.
The bad news is it will also break all C++ extensions, which frankly I'm not looking forward to (both as a developer of said extensions, and a user).
The much, much bigger issue is the native modules in npm. They all basically have to be ported by hand, and only a handful actually have been. So, transitioning to the next version of node will be an exercise in masochism for us makers.
On the other hand, improving V8 with breaking changes is the V8 team's perogative and I trust they're doing it for the right reasons.
In theory, this should allow them greater flexibilty to iterate and refine the language over time without the negative backlash that we're seeing here.
By the way, thank you for all your work. It took me quite a while to wrap my head around the template craziness you use in cvv8 but it turns out being pretty awesome. We have a huge API surface we're using cvv8 on and so far it's working great.
IMHO probably the best approach that I haven't seen anyone but the chromium project use would be a bindings compiler that takes WebIDL and generates wrapper code. I started down that path before diving into cvv8, but didn't understand well enough what my compiler should output. May have to revisit that project at some point if we want to upgrade beyond node 0.10.
Anyway... you "could" write a wrapper which generates cvv8 bindings. i did that long ago in a predecessor to generate about a hundred ncurses bindings. But... that assumes cvv8 is usable, which it is not with current v8 versions :`(.
It doesn't build outside of the WebKit tree, though... (but there are some scripts which should in theory build only jsc; I think they want all the deps to WebKit, etc, however).
As far as APIs, JSC has provided a completely API and ABI stable C API for 7-ish years, and there's an ObjC API built on top of that now. Unfortunately the nature of C APIs for interacting with language runtimes makes it somewhat clunky and hard to use perfectly - C++ makes this easier as you can make types with constructors and destructors to make a lot of the otherwise manual work (ref()/deref(), etc) entirely automatic. Unfortunately C++ makes it easy to make an API that has a stable interface, but still isn't ABI stable.
A bigger concern for me personally is that the jsc shell lacks typed arrays, https://bugs.webkit.org/show_bug.cgi?id=119828
edit: i should have said 'full spec for typed arrays', see the linked issue
I believe the "need all of webkit-gtk" was a pile of sadness in build-jsc + automake that may have been fixed recently. I'm sure Zan, Xan, or Michel would be happy to help if it's still borked. There are _some_ platform requirements that make a generic "linux" not work, as we build on the platform support libraries for threads, unicode, etc so JSC may have random looking dependencies on such
I am not even sure how to try to build jsc by itself on linux, i couldn't find any instructions (online or in the dir)? All online discussions i found said i need to build all of webkit.
Tools/Scripts/build-jsc _should_ build just jsc.
Seems that nobody has tried that in a long time, or who knows why it references something in C:\tools
`\WebKitLibraries\win\tools\vsprops`
Into `C:\tools\vsprops`
Worked for me.
https://groups.google.com/d/msg/v8-users/6kSAbnUb-rQ/e-GI0b1...
Changing all callbacks that return Handle<Value> to return void and instead pass the return value in as a parameter.
https://github.com/drcarney66/v8-backport
Amount of typing one needs to do is minimal, I think.
Edit: Every one of the downvotes this post gets are because this post runs counter to the HN echo chamber. I challenge someone to present an argument to explain otherwise. You've soaked yourself in outrage, and hell if anyone will say anything that may disagree with all that anger boiling up inside you. So you see some green nick and click downvote.
Happy Hacking!
[1]http://code.google.com/p/v8-juice/w/list [2]http://code.google.com/p/v8-juice/wiki/CommentaryOnV8 [3]http://marc.info/?l=freedos-dev&m=94670703232745 [4]http://web.archive.org/web/*/http://dominic.liquid3.com.au/j... [5]https://developer.mozilla.org/en-US/docs/Web/JavaScript [6]http://en.wikipedia.org/wiki/JavaScript#Uses_outside_web_pag... [7]http://spiderape.sourceforge.net/ [8]http://www.jsdb.org/ [9]https://developer.mozilla.org/en-US/docs/SpiderMonkey [10]http://code.google.com/p/v8/w/list
It seems ironic to me that you make this statement (which would you could not possibly know to be true without being omiscient), and then add:
"... hell if anyone will say anything that may disagree with all that anger boiling up inside you."
While there are no doubt many ex-Google (and ex-other-high-profile-company) employees who put out poorly-worded and sometimes poorly-defended rants which in the end serve little purpose other than to vent their own frustration, I do not think you can lump Stephan's post in with them.
I have followed Stephan's work for many years. He is one of those rare developers who actually enjoys putting out high volumes of good documentation (which he readily admits on his own web sites). He appears to be passionately invested in every open source project he contributes to, and is quick to invest large quantities of his own time in helping others to use the code he has made generously available for others to use (much of it in the public domain, btw). I do not always agree with everything he says, but I give him great credit for his generousity.
While he may like to see himself given some credit for his contributions (who doesn't), he doesn't much struck me as the narcissistic type. Overall the interactions I've had with him (and the ones I've read online) have been quite civil. Occasionally, such as in this post, his passion for what he believes comes to the fore, and I suppose that might turn some off. However, I don't consider this post to be too far over-the-top, and it is obvious that he is trying to express a great deal of frustration while attempting to remain as civil as possbile. I think he at least mostly achieved that goal.
It is a difficult thing to abandon a project you have invested a lot of time in for over four years, especially when you feel the project could have easily been so much more if circumstances beyond your control would have been different.
Also, I don't think posts such as Stephan's ever need to have an effect on the offending party's behavior (in this case, Google and/or the V8 developer). There are many developers who have an interest in using and/or embedding V8 in their software, and having these insights into possible problems with doing so is worthwhile information by itself. The fact that Node.js uses V8 makes this information valuable in my opinion.
IMHO you owe it to yourself to take a look at Stephan's work (both inside and outside the v8-juice project), and perhaps form a different opinion.
PS: i don't always agree with everything i say, either ;)
Oh, and you're very welcome.
BTW, the post should read "he doesn't much strike me as ...", "not he doesn't much struck me as ..." -- one of the problems of editing a post too many times. I can't figure out how to edit the post, so I guess I'll just leave it for humor's sake. :-D