Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
PERF: Memoize lookups from SIDE_MODULE into MAIN_MODULE #6437
In running Numpy benchmarks in WebAssembly, I noticed that particularly for the benchmarks that are much slower than native, a large fraction of the time was spent looking up symbols in the main module from the side module (at least I think that's what this code does):
By memoizing the lookup, that significantly speeds things up.
(x scale is slowdown factor of WebAssembly vs. native. Grey is before this change, blue is after).
Wow, incredible that this speeds things up so much! Aside from being a huge speedup, it also brings us into the 4x or so slowdown area on average, which is surprisingly good given native can use simd.
About this code, the reason it tries to by dynamic is it originated from code that lets a module load code from a module loaded after it. However, this code here is literally just for the main module itself, so it's a moot point, and this optimization is valid. We can simplify it a little more, even (probably with no speedup, though), I'll comment in the code.
Apr 11, 2018
19 checks passed
@lukewagner Do you mean using function pointers and indirect calls? It's possible that would be faster than the current thunks. But I thought the long-term plan for dynamic linking was to have cross-module calls be fast direct ones? The current code tries to be close to that.
Yeah, in the case of the code here, the hope is to improve it into a direct call, which should be possible since it's a call from a shared module into the main module, and the main module instantiates the shared module. However, the code we emit for the shared module doesn't know it'll be a call into the main module (might be another shared module), so there's something to figure out there that I haven't had time to look into.