Add option to force table elements to be considered immutable

Open
#4,256 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

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

Research direction

Start by reviewing the referenced Directize.cpp optimization and how Emscripten tables are imported or exported. Investigate whether static table elements can safely be treated as immutable despite JavaScript adding elements, then benchmark the relevant workloads. Done means a validated option such as --immutable-table-elems with evidence that the optimization is worthwhile.

Written by the indexing model from the issue text.

Description

Binaryen has some optization that is unlocked when the table is immutable:

https://github.com/WebAssembly/binaryen/blob/0bec0a4bbaf4859bb4c7a2f1c4ecda60ccab72f2/src/passes/Directize.cpp#L174-L178

With emscripten however, the table is always either imported or exported so this optimization is never enabled in practice.

However, emscripten usage of the table from JS never actually mutates existing table elements. It will read from the table and add new elements but it will never mutate of remove table elements generated by C/C++ (wsam-ld).

Perhaps we could have an options such as --immutable-table-elems which would force binaryen to consider static table elements to be immutable? We should run some benchmarks to see if this is worth while.

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

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.

More from WebAssembly/binaryen

All issues in WebAssembly/binaryen

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.