Skip to content

Speed up local variable analysis by reusing previous results - #9175

Open
jkbz64 wants to merge 1 commit into
WebAssembly:mainfrom
jkbz64:fix/local-graph-query-cache
Open

jkbz64 wants to merge 1 commit into
WebAssembly:mainfrom
jkbz64:fix/local-graph-query-cache

Conversation

@jkbz64

@jkbz64 jkbz64 commented Sep 29, 2026 •

Copy link
Copy Markdown

Related #7644 and potentially fixes (?) #7319

wasm-opt on my tree-sitter grammar takes more than 10 minutes, this is due to repeated searches through the same blocks during local variable analysis as profiling pointed out to ssa-nomerge taking up 98%+ of cpu time.

This change reuses completed results. On my file, -Os went from about 10 minutes to 6-7 seconds, with byte-for-byte identical output, this is a slop fix so I'm kinda being a meat proxy here, sorry (was asked to open the PR so I did).

Steps to reproduce

git clone https://github.com/usagi-coffee/tree-sitter-abl --depth=2
cd tree-sitter-abl
tree-sitter build -w

or pickup a .wasm file from releases and run wasm-opt on it w/ -Os.

Save completed searches in LocalGraph and reuse them when finding which
assignments reach a local variable read. Stop searching earlier blocks when
a saved result is available and no assignment in the block overrides it.

Save results only after the search finishes so loops cannot reuse incomplete
results. Apply this to both eager and lazy local variable analysis.

Add tests for loops, overwritten locals, initial values, unreachable code,
and different query orders.
@jkbz64
jkbz64 requested a review from a team as a code owner September 29, 2026 23:08
@jkbz64
jkbz64 requested review from aheejin and removed request for a team September 29, 2026 23:08

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant