-
Notifications
You must be signed in to change notification settings - Fork 18k
wasm: 3x performance overhead of using webassembly in node 8 #26277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If you want to skip the docker build |
If I understand this correctly, there is very little "actual" webassembly here. This is still running a node http server, in a very roundabout fashion. What I believe you are seeing is the js-wasm transfer overhead. /cc @neelance |
I bet a good portion of it is due to the Line 319 in 5cb1b17
Performance optimizations were not yet in scope. |
@neelance I played around to see if I can shave off time. Removing setTimeout didn't change too much. I ran it through chrome profiler and it seems the hotspot is loading strings out of the memory blob and decoding them on the js side. The strings in my example on the method names i want to call on my js values. Perhaps some sort of constant pool is in order? |
Maybe. We might even need some additional type like this:
This way, we could avoid referencing a method by string each time. |
That would be cool! I dont know how safe this is but I changed loadString in the wasm_exec to have a js side string cache. Its not bombing... and now im getting 8-10k requests/second, vs original implementation 5540.49. const strCache = {};
const loadString = (addr) => {
const saddr = getInt64(addr + 0);
const cache = strCache[saddr.toString()];
if (cache) {
return cache;
}
const len = getInt64(addr + 8);
const ret = decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
strCache[saddr.toString()] = ret;
return ret;
} |
This will now fall under #32591. Closing this in favor of that. |
Im really not sure where to submit this issue, golang, node or chromium. So I am starting here. Feel free to close the issue and provide feedback if you think I should go elsewhere.
What version of Go are you using (
go version
)?Master Head // b001ffb
Does this issue reproduce with the latest release?
N/A latest release does not have wasm.
What operating system and processor architecture are you using (
go env
)?wasm on linux
node 8.11
What did you do?
I built a connection from webassembly to node http and benchmarked it against native http version
recipe for reproducing
https://github.com/trashhalo/go_wasm_node_http
benchmark results
https://gist.github.com/trashhalo/b2f120fb9d20bd4003bf125c0200b601
node hello world
https://gist.github.com/thebinarypenguin/122cda772438c80ad683
What did you expect to see?
I expected a performance hit but not one so large
What did you see instead?
A 3x hit to performance of equivalent javascript code.
The text was updated successfully, but these errors were encountered: