Live data from Hacker News

Optimizing the Ion compiler back end

spidermonkey.dev

21–30 of 45 posts

Re: Optimizing the Ion compiler back end

#22
post #20

Wow, that dominator tree algorithm I wrote as an intern ( https://bugzilla.mozilla.org/show_bug.cgi?id=666426 ) seems to have lasted 13 years! At the time we assumed that graphs would be small enough to not warrant the constant factor against Lengauer-Tarjan. ...And of course, browser-based apps have gotten much bigger since then. Semi-NCA hadn't even been published yet and seems like the clear choice nowadays, so I'…

[deleted]

Re: Optimizing the Ion compiler back end

#23

Earlier quoted context omitted.

> Is there any AOT WebAssembly compiler that can compile Wasm used by websites? This doesn't really make sense, given that the wasm used by websites is going to import a bunch of JS functions as dependencies. You're not going to have those available in any native environment. > Is it really the case that browsers have default-enabled all sorts of extensions that are not yet widely supported by the rest of the ecosyst…

I think one of the interesting aspects of WebAssembly compared to JavaScript is that it can be efficiently AOT-compiled. I've been interested in investigating AOT compilation for a browser (perhaps there is a distant/alternative future where web browsing does not require a JIT), but maybe Wasm AOT compilers aren't really there yet.

Functionally what browsers do under the hood is AOT compilation but not in the way that i.e. Wasmtime is. The following is my knowledge that may no longer be accurate, but this is the sort of model we planned for when designing WASM to begin with:

Browsers do a on-demand 'first tier' compilation for fast startup, and in the background using threads they do a high quality AOT compilation of the whole module. That high quality AOT compilation is cached and used for future page loads.

It is possible to use a JIT model for this but AFAIK it is typically not done. In some configurations (i.e. lockdown mode) WASM is interpreted instead of AOT compiled.

Re: Optimizing the Ion compiler back end

#24

Earlier quoted context omitted.

I think one of the interesting aspects of WebAssembly compared to JavaScript is that it can be efficiently AOT-compiled. I've been interested in investigating AOT compilation for a browser (perhaps there is a distant/alternative future where web browsing does not require a JIT), but maybe Wasm AOT compilers aren't really there yet.

Functionally what browsers do under the hood is AOT compilation but not in the way that i.e. Wasmtime is. The following is my knowledge that may no longer be accurate, but this is the sort of model we planned for when designing WASM to begin with: Browsers do a on-demand 'first tier' compilation for fast startup, and in the background using threads they do a high quality AOT compilation of the whole module. That high…

> It is possible to use a JIT model for this but AFAIK it is typically not done.

Isn't this what the last line of the article is hinting at? > our WebAssembly team is making great progress rearchitecting the Wasm compiler pipeline. This work will make it possible to Ion-compile individual Wasm functions as they warm up instead of compiling everything immediately.

Re: Optimizing the Ion compiler back end

#25
post #4

Moral of the story: First, use an array. If an array doesn't work, try something else.

It's definitely the case that in many scenarios, the right data structure is an array, since you'll have work dominated by gets and sets. However, the OP has one scenario where the opposite was true - they were using a dense bitset that needed to be obscenely huge because of degenerate code in the wasm module, so swapping to a sparse container was a win. In the end you just have to profile and understand your data.

To your point, profile your data as you would your code.

A sorted array of bit locations would represent a sparse bit set well enough to start, with O(N) storage and O(log N) access. Once the sets became large and/or dense, another data structure could be considered.

Re: Optimizing the Ion compiler back end

#27
What is MIR in this context? On the one hand, given the mention of Cranelift, it seems like it could be referring to the Rust compiler's intermediate representation, but given the context perhaps it's referring to an independent intermediate representation that also just happens to be called MIR?

Re: Optimizing the Ion compiler back end

#28
post #20

Wow, that dominator tree algorithm I wrote as an intern ( https://bugzilla.mozilla.org/show_bug.cgi?id=666426 ) seems to have lasted 13 years! At the time we assumed that graphs would be small enough to not warrant the constant factor against Lengauer-Tarjan. ...And of course, browser-based apps have gotten much bigger since then. Semi-NCA hadn't even been published yet and seems like the clear choice nowadays, so I'…

> Semi-NCA hadn't even been published yet and seems like the clear choice nowadays[.]

For those who are awkwardly lingering and casting longing glasses at the entrance door of compiler engineering like I am, and who were just as dismayed by this sentence, it wasn’t “properly” published but looks to have been described in a thesis from 2005[1] and in an extended abstract (ugh) before that[2].

But also, the reduction of RMQ to NCA, really?.. Ouch. I’m having flashbacks to my (very brief) competitive programming days, and not the good kind.

[1] https://www.cs.princeton.edu/research/techreps/TR-737-05

[2] https://www.cse.uoi.gr/~loukas/index.files/dominators_soda04...

Re: Optimizing the Ion compiler back end

#29
post #20

Wow, that dominator tree algorithm I wrote as an intern ( https://bugzilla.mozilla.org/show_bug.cgi?id=666426 ) seems to have lasted 13 years! At the time we assumed that graphs would be small enough to not warrant the constant factor against Lengauer-Tarjan. ...And of course, browser-based apps have gotten much bigger since then. Semi-NCA hadn't even been published yet and seems like the clear choice nowadays, so I'…

Amusingly, the LLVM implementation was also written by an intern at one point :)

Semi-NCA was actually published back then, just not in the cited paper.

See "Finding dominators in practice", published in 2004, section 2.3. So two decades ago.

The main advantage of Semi-NCA (and why LLVM uses it) is that it makes for a good incremental update algorithm. See https://reviews.llvm.org/D34258

Truthfully, as much as I love Cooper and friends (they were responsible for a lot of very thoughtful, well engineered algorithms at a time when lots of stuff was just "here's some research i think is better"), the "simple" dataflow based algorithm was never worth it.

Part of the thing i was good at way back then was keeping track of all of the research in compiler opts and which was any good - most of their stuff is very good.

I used to go through every paper that came around and keep an up to date library of ones worth looking at (both now and in the future) that a bunch of folks used. This was harder back in the days of nobody really publishing code, i used to have to write a ton of prototype implementations to see which numbers were real and which were BS because they compared against crappy implementations or whatever.

SEMI-NCA was an obvious win - it was simple enough to implement and test, equally as fast as what existed now, and could easily be extended to incremental updates.

If you want to see what it takes to do incremental updates with LT, take a look at GCC's dominator update code back around that time period (I think it's unchanged since then, actually, but i haven't looked in a few years). There were a fairly small number of people who could understand the data structures and algorithms involved.

Re: Optimizing the Ion compiler back end

#30
post #20

Wow, that dominator tree algorithm I wrote as an intern ( https://bugzilla.mozilla.org/show_bug.cgi?id=666426 ) seems to have lasted 13 years! At the time we assumed that graphs would be small enough to not warrant the constant factor against Lengauer-Tarjan. ...And of course, browser-based apps have gotten much bigger since then. Semi-NCA hadn't even been published yet and seems like the clear choice nowadays, so I'…

> Semi-NCA hadn't even been published yet and seems like the clear choice nowadays[.] For those who are awkwardly lingering and casting longing glasses at the entrance door of compiler engineering like I am, and who were just as dismayed by this sentence, it wasn’t “properly” published but looks to have been described in a thesis from 2005[1] and in an extended abstract (ugh) before that[2]. But also, the reduction o…

It was published prior to that in a paper named "Finding dominators in practice", published in ESA 2004[1].

For once, the title is not actually an oversell, it actually covers that topic quite well for a conference paper.

[1] https://link.springer.com/chapter/10.1007/978-3-540-30140-0_...

Post reply on HN