binaryen icon indicating copy to clipboard operation
binaryen copied to clipboard

[Custom Descriptors] Optimize RefCast to RefCastDesc in GlobalStructInference

Open kripken opened this issue 3 months ago • 6 comments

kripken avatar Sep 18 '25 18:09 kripken

That is something the pass verifies,

https://github.com/WebAssembly/binaryen/blob/46b37d348c4025c7e618dd4507d96b569df5f5ea/src/passes/GlobalStructInference.cpp#L113-L115

Unless I misunderstood you?

kripken avatar Sep 19 '25 14:09 kripken

Great, I had forgotten we already did that.

tlively avatar Sep 19 '25 14:09 tlively

There are some TODOs here, but the larger question is whether this seems worthwhile. I see a 1% code size regression on j2cl for example - do we expect the benefit to be larger than that? @tlively @jakobkummerow

kripken avatar Sep 19 '25 16:09 kripken

This is primarily a performance improvement. ref.cast_desc is faster than other casts.

tlively avatar Sep 19 '25 17:09 tlively

Makes sense, but do we think it is fast enough to justify a 1% size regression? Given that iiuc we think the VM can do much of this too.

kripken avatar Sep 19 '25 18:09 kripken

This should only be run at the very end, manually - running it in every -O3 causes code size increases for various reasons (1% increase affects inlining, and also we end up with more exact types, which inhibit merging of locals etc.), that accumulates, and it does not enable other toolchain opts anyhow.

kripken avatar Sep 24 '25 20:09 kripken