WebAssembly / WebAssembly/binaryen

Recognize table initialization code in start function and be able to devirtualize based on it

Open
#8,869 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 19h
Merged PRs (30d)
69

Description

Producers of wasm code prefer small binary size and may use table.fill instructions to initialize parts of a table (or other constructs, like a loop of increasing indices to initialize i31ref table) instead of emitting large element segments.

It would be nice if binaryen offered a flag (e.g. --trust-table-init-code or something like that) that would make it recognize this pattern and treat it as iff the regions were initialized in element sections and therefore be immutable and allow devirtualization / loads of the table to be folded away.

It could be an opt-in flag.

(In some sense an export of a table - e.g. in multi module scenarios - is in similar situation. One may want with a wasm-merge+wasm-opt+wasm-split the ability to devirtualize -- and would have an assumption that the exported table isn't used by 3rd party modules)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how Binaryen handles table.fill, start-function initialization code, and element segments, then compare that with the existing devirtualization and table-load folding behavior. Define the opt-in flag semantics and verify that recognized initialized regions are treated like immutable element-section regions without changing unrecognized tables.

Written by the indexing model from the issue text.

Assessment

Tech stack
wasm
Domain
compilers, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.