Inlining: --inline-max-combined-binary-size is not enforced when several functions are inlined into one caller in the same iteration
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 58/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- cpp, wasm
- 領域
- compilers, performance
調査の方向性
Read src/passes/Inlining.cpp, especially isUnderSizeLimit and the code that selects inlining actions during an iteration. Trace how multiple chosen actions affect a target's combined size, then add or update a regression test for several callees inlined into one caller. Done means the combined-size limit is respected in that case while the single-callee behavior still works.
索引モデルが issue の本文から書いたものです。
説明
Summary
--inline-max-combined-binary-size (default 409600) is not enforced when several functions are inlined into the same caller in one inlining iteration. isUnderSizeLimit in src/passes/Inlining.cpp checks infos[target].size + infos[source].size for each chosen action, using the sizes measured when the iteration started, so every check passes against the caller's original size. With single-caller functions, which --one-caller-inline-max-function-size admits at any size by default, a caller with many such callees absorbs all of them in one round and grows far past the limit.
In a large program compiled from .NET, a dispatch function calling about 3,500 single-caller functions became one 12.3 MB function after -O3. That is over the 7,654,321-byte function body limit that V8 and wasmparser enforce, so the optimized module no longer validates.
Reproduction
gen.py N BODY writes a module whose exported dispatch calls each of N functions exactly once through a br_table. Each callee has that one caller and a straight-line body of about BODY instructions.
import sys
n, body = int(sys.argv[1]), int(sys.argv[2])
out = ["(module", " (memory 1)"]
for i in range(n):
lines = [f" (func $f{i} (param $x i32) (result i32)", " (local $a i32)", " (local.set $a (local.get $x))"]
for j in range(body // 8):
lines.append(f" (i32.store offset={(j * 4) % 4096} (local.get $a) (i32.add (i32.mul (local.get $a) (i32.const {i * 31 + j})) (i32.const {j})))")
lines.append(f" (local.set $a (i32.xor (local.get $a) (i32.load offset={(j * 8) % 4096} (local.get $a))))")
lines.append(" (local.get $a))")
out += lines
blocks = "".join(f"(block $b{i} " for i in range(n))
out.append(" (func $dispatch (export \"dispatch\") (param $k i32) (param $x i32) (result i32)")
out.append(" " + blocks + "(br_table " + " ".join(f"$b{i}" for i in range(n)) + f" $b{n-1} (local.get $k))")
for i in range(n):
out.append(f" ) (return (call $f{i} (local.get $x)))")
out.append(" ))")
print("\n".join(out))
python3 gen.py 20 13600 > small.wat
wasm-as small.wat -o small.wasm
wasm-opt small.wasm -O3 -o out.wasm
With wasm-opt version 132 (version_132-8-g8d9412ef6):
| Module | Functions | dispatch body |
|---|---|---|
| input: 20 callees of 45,718 bytes each | 21 | 187 bytes |
-O3 |
1 | 846,018 bytes |
-O3 --inline-max-combined-binary-size=409600 |
1 | 846,018 bytes |
Every callee is inlined, so dispatch ends at about twice the limit. At larger scale (gen.py 3000 400) dispatch grows from 32,752 bytes to 3,601,560 bytes.
The per-inlining check does work for a single large callee: with gen.py 1 140000 (one 489,862-byte callee) the callee is left as a call.
Expected
Inlining into dispatch stops once the combined size reaches the limit, after about eight callees here, and the remaining callees stay as calls.
Possible fix
Account for the inlinings already chosen for a target in the same iteration: for example, keep a running size per target that each chosen action adds to, and check against it in isUnderSizeLimit, or update infos[target].size when an action is chosen. isUnderSizeLimit is unchanged on main.
As a workaround we mark the excess callees never-inline (@metadata.code.inline 0) before running wasm-opt.
- 主要言語
- WebAssembly
- スター
- 8.7k
- フォーク
- 913
- 平均マージ
- 2日 14時間
- マージ済み PR(30日)
- 92
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
WebAssembly/binaryen のほかの issue
-
DAE2 crashes on call.without.effects with a non ref.func expression対応中かも @stevenfontanella が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
WebAssembly/binaryen#9404 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
WebAssembly/binaryen#9135 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 半日 初心者へのやさしさ 76/100
WebAssembly/binaryen#9018 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
Remove `call.without.effects` intrinsic対応中かも @stevenfontanella が 2 日前に担当しました。 オープン
WebAssembly/binaryen#9399 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Add a pass to relax nullabilities of definitions対応中かも @stevenfontanella が 13 日前に担当しました。 オープンenhancement
WebAssembly/binaryen#9352 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
WebAssembly/binaryen の issue をすべて見る
似ている issue
-
area:compiler effort:S impact:med platform:windows type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
area:Analysis enhancement
難易度 1/5 1〜3時間 初心者へのやさしさ 69/100
facebookresearch/atlas-lean#5118 ·
メンテナーはふだん 1 日以内に返信
-
bug css P3
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
fizzbee-io/fizzbee#478 ·
メンテナーはふだん 1 日以内に返信