Pass around a DataView instead of individual kind/payload fields - #24
Pass around a DataView instead of individual kind/payload fields#24j-f1 wants to merge 4 commits into
Conversation
The use of a DataView reduces function paramater count. There are now only two payload slots. Numbers use them as a single Double, while every other type just uses them as two UInt32s Co-Authored-By: Manuel <unkaputtbar@users.noreply.github.com>
|
Note: I dropped the size of each object in memory from 24 down to 12. I’m not exactly sure why they were 24 bytes long before since kind + payload1 + payload2 = 12 bytes and payload3 = 8 bytes which only add up to 20. If I’m missing something about the memory layout, I’d be happy to correct it. |
|
Thanks for your cooperation. Did you check performance benchmark suite? You can check benchmark by I found some performance regression on number interoperation. Before After I'm still reviewing the changes, so please wait for a while. |
The additional 4 byte is for |
| const exports = this.instance.exports as any as SwiftRuntimeExportedFunctions; | ||
| const argc = args.length | ||
| const argv = exports.swjs_prepare_host_function_call(argc) | ||
| const uint32Memory = new Uint32Array(memory().buffer, argv, args.length * 3) |
There was a problem hiding this comment.
This uint32Memory is not used
|
I think the regression is due to the indirection of payloads access. |
That definitely seems to be the case! I’m not sure why they switched to passing in the
Ah, that makes sense! Since we’re not using C doubles anymore (we’re just encoding them as two ints), this shouldn’t be an issue, right? |
Thanks ❤️
Yes, I think it's ok. |
|
Ok, so I did a test where I removed all the
|
|
Ultimately I’d be fine just closing this if it has no real benefit |
|
Hmm, the benchmark results show that decoding number from two 32bit payloads is slower than passing 20 byte payloads directly. I think we need to optimize the payloads, but this approach seems a little difficult. |
|
This might be a good thing to explore in the future when there’s better tooling to analyze perf but I don’t have a good rationale for this PR right now. Not really sure why I opened it in the first place. Thanks for sticking with me as I figure out exactly which things need to be brought over! |
Also change memory layout for numbers:
There are now only two payload slots. Numbers use them as a single Double, while every other type just uses them as two UInt32s
Originally part of #22.