6 ms·
Off-main-thread HTML parsing in Servo
- vmarsy 9y agoI really liked the blog post and was interested to see the end results but... > I hope to publish another blog post describing [speculative parsing] thoroughly, along with details on the performance improvements this feature would bring. Isn't there any preliminary results on the perf improvements this would bring? I understand that the % of time when the speculative parsing succeeds (instead of having to roll back to a sequential parsing) can't be know easily, since it'll be based on the testing of a large number of real-world web pages, but I'd love to see just 2 simple examples: * One full of `document.write`, so we can have an idea of the time lost in case of failed speculation * One 'embarrassingly parallel' dom tree where the speculation should pay off the most. That would give us a good idea of worst case / best case results.
- kevingadd 9y agoWith things like this sometimes they do the work without preliminary perf numbers because other browsers have already done it successfully. IIRC, at least one production browser already does off-main-thread parsing.
- Touche 9y agoDo you know which one? Is it speculative parsing like this one or does it stop at scripts?
- bla2 9y agoPretty sure all WebKit-based browsers (including chrome) do this. I'd guess they block if needed, but I'm not sure.
- esprehn 9y agofwiw WebKit never turned on the threaded html parser (and deleted it after the fork [1]) and Blink removed it a bit ago too [2]. In Chrome we measured it across a number of sites and found that the time saved from background tokenization wasn't benefiting real world content enough to justify the cost and that in some situations it actually made things worse. That's not to say Servo shouldn't try it of course! Part of having a healthy multi-browser ecosystem is each browser trying lots of ideas and coming up with new solutions to problems that were encountered in other implementations. [1] http://trac.webkit.org/changeset/162260/webkit http://trac.webkit.org/changeset/162260/webkit (the number cited here is a joke :P) [2] https://groups.google.com/a/chromium.org/forum/#!topic/loading-dev/_cXkjQ0-L_E https://groups.google.com/a/chromium.org/forum/#!topic/loadi... (see also the design doc linked from the email)
- krzat 9y agoI guess one of goals of Rust is to make these sort of optimisations viable (compiler provides safety nets). Will be nice to see what they can do.
- hsivonen 9y agoGecko has had off-the-main thread HTML parsing since Firefox 4. Docs: https://developer.mozilla.org/en-US/docs/Mozilla/Gecko/HTML_parser_threading https://developer.mozilla.org/en-US/docs/Mozilla/Gecko/HTML_... WebKit/Blink put fewer parts of the HTML parser off the main thread, so negative results should not be taken to apply to more comprehensive approaches.
- ibotty 9y agoI don't get the joke. Were these defines never used? Did the commit removing the threaded html parser happen before?
- bla2 9y agoI'd wager the feature required fewer than 8.8 million lines of code :-)
- pcwalton 9y agoGecko/Firefox.
- deleted 9y ago[deleted]
- jgraham 9y agoPresto (the old Opera engine) had a mode called "delayed script execution" which would speculate even harder than the gecko/servo approach. As I understand it — which might well be incorrectly — it would continue treebuilding after a script tag, and then if the script ran a document.write it would check if it produced something that wouldn't affect subsequent tokenisation (or, presumably alter the treebuilding state) and if so patch the tree in-place rather than throwing it away and restarting. It was never debugged enough to be turned on on desktop, but I think it was considered useful enough to ship on mobile in the days when mobile performance was significantly worse than it is today. In particular, on a network where request latency is high having to pause treebuilding for scripts to download can significantly increase the time until it's possible to paint anything at all on the screen.
- gsnedders 9y agoMy memory of DSE is that it parsed the entire document prior to doing any script execution; it didn't merely run the script when it became available. That said, I probably touched it only marginally more recently than you.
- euyyn 9y agoI wish he went into more detail explaining his solution to the synchronous queries, as the linked gist implies much more knowledge of Servo's internals than I have.
- Touche 9y agoIs it possible to use Servo yet? Last time I tried to use it, it was unusably slow on all websites I tested with. It was always weird to read about how fast it was when my (albeit limited) experience was the opposite. Is browser.html still the preferred way to test?
- dbaupp 9y agoAs I understand it, a lot of pieces critical for real world use are really just minimum viable implementations to allow Servo to work end-to-end and feed data into the interesting parts. In particular, things like the network stack don't benefit nearly as much from aggressive parallelism and so little effort has been focused on them, not even bringing them up to level with the techniques other browsers use.
- Touche 9y agoThanks, I can understand how that might be the case (that many parts are MVIs, as you said). My issues were never with things like networking, it was more that scrolling was really bad, and stuff rendered slowly.
- pcwalton 9y agoWebRender has matured a lot lately; it's even in Firefox nightlies behind an about:config preference. That said, there are still rough edges. If you see rendering slowness, feel free to file issues on http://github.com/servo/webrender http://github.com/servo/webrender. There are no silver bullets for performance, only lots of lead bullets. I'm confident that parallelism via GPU and multicore is a large architectural win. But lots of making the Web fast involves a ton of little special case optimizations that just need to be implemented. That's how Stylo went: promising benchmarks and a mediocre user experience at the research stage turned into great benchmarks and a great user experience with production engineering work.
- DiabloD3 9y agoSo, anyone try Firefox Nightly lately, with Stylo finally landed in there? The browser actually feels fast now, I think I've finally made my decision to dump Chrome.
- Garbage 9y agoI have been using Stylo for some time now. I have faced exactly zero problems. I think it's rock solid. I don't think it's the default CSS style system though. You can enable it using layout.css.servo.enabled to true in about:config
- KitDuncan 9y agoYou can already enable this flag and Firefox stable, but I don't think it takes effect yet.
- NiLSPACE 9y agoIt only works in Firefox Nightly. The flag exists in Beta and Stable, but since Stylo isn't compiled with these versions the flag doesn't actually do anything.
- infogulch 9y agoAre you sure? I thought I saw a FF dev mention right here that the flag is available in stable just a couple days ago.
- DiabloD3 9y agoFrom what I can tell, Beta 56 has it (but you have to enable it), Nightly 57 has it (https://bugzilla.mozilla.org/show_bug.cgi?id=1330412 https://bugzilla.mozilla.org/show_bug.cgi?id=1330412 is tracking when it'll be enabled by default), and Stable 55 does not have it at all (although the pref might be there).
- leshow 9y ago
- lewisl9029 9y agoLast time I checked, the Servo team also had plans to execute JS off the main thread and introduce async versions of DOM APIs to enable better parallelism: https://news.ycombinator.com/item?id=9011215 https://news.ycombinator.com/item?id=9011215 Servo is by far the technology I'm most excited about as a frontend developer. It will be a complete game changer for web performance once all the pieces are in place.
- pcwalton 9y agoThere isn't really a main thread in Servo, because WebRender, layout, and JS/DOM per origin all live in separate threads.
- tmzt 9y agoWould you consider exposing an RPC interface to JavaScript and/or WASM to enable faster vdom operations? Also, after reading that old HN comment, do you think adding something like RenderEvent with values like client size already defined would make sense? Servo feels like a great platform for experiments like this which, if successful, could move into Firefox.
- andy_ppp 9y agoI wish browser vendors would make stand at this point and say in 1 year all major browser engines will stop supporting document.write - it's horrible for developers to use and no-one I know advocates it - but I'm fairly sure ad networks still use it for no reason whatsoever. The implementation of browsers is already difficult enough! It's great to see the lengths Servo is going to to be compatible, but on this one I say warn developers and deprecate this feature that no-one in 2017 should ever use.
- rossy 9y ago> it's horrible for developers to use and no-one I know advocates it I've seen developers advocate for document.write to inject locally-hosted JavaScript as a fallback for when CDNs are down: https://www.hanselman.com/blog/CDNsFailButYourScriptsDontHaveToFallbackFromCDNToLocalJQuery.aspx https://www.hanselman.com/blog/CDNsFailButYourScriptsDontHav... I definitely don't agree with this method, but there you go. Apparently ASP.NET 4.5 will even insert this pattern automatically.
- CrystalGamma 9y agoYou could still insert <script> elements, you just wouldn't do it with document.write().
- pygy_ 9y agoI may be wrong, but I think that document.write() will load the script synchronously while inserting a `script` element will not.