Bug 270376

Summary: [JSC] Decode local indices at runtime in WASM in-place interpreter
Product: WebKit Reporter: David Degazio <d_degazio>
Component: WebAssemblyAssignee: David Degazio <d_degazio>
Status: RESOLVED FIXED    
Severity: Normal CC: webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Description David Degazio 2024-03-01 13:43:49 PST
rdar://123720682

Local indices are encoded using ULEB128 in WebAssembly. In the work-in-progress in-place interpreter, we currently handle (U)LEB128 decoding during validation, and generate fully decoded indices in the metadata. Most functions, however, have very few locals in WebAssembly - WASM binaries that have gone through optimizations tend to treat locals like registers, and in all of JetStream 2 there is no local index that takes more than two bytes to encode. Since it's extremely common local indices will be single-byte, then it makes a lot of sense to skip the metadata entirely for all local instructions, instead having a single-byte fast path combined with an infrequently-taken ULEB128 decode at runtime. Since getting and setting locals makes up something like 1/3 of all WASM instructions in typical binaries, this should substantially reduce the size of the metadata generated for the in-place interpreter, and hopefully improve runtime performance as well.
Comment 1 David Degazio 2024-03-07 13:21:37 PST
Pull request: https://github.com/WebKit/WebKit/pull/25596
Comment 2 EWS 2024-03-07 17:48:18 PST
Committed 275815@main (bfe017002276): <https://commits.webkit.org/275815@main>

Reviewed commits have been landed. Closing PR #25596 and removing active labels.