[NFC] cache repeated tree walks to avoid O(N^2) in optimizeTerminatingTails in CodeFolding#8602
Draft
Changqing-JING wants to merge 1 commit intoWebAssembly:mainfrom
Draft
[NFC] cache repeated tree walks to avoid O(N^2) in optimizeTerminatingTails in CodeFolding#8602Changqing-JING wants to merge 1 commit intoWebAssembly:mainfrom
Changqing-JING wants to merge 1 commit intoWebAssembly:mainfrom
Conversation
7454548 to
a1924cf
Compare
a1924cf to
c2c710f
Compare
c2c710f to
82d92bb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In
optimizeTerminatingTails,canMoverepeatedly walked the entire function body to compute branch targets and find Try/TryTable nodes, causing O(N^2) behavior. This change caches those results lazily on first use viacanMoveWithCachedBodyInfo, and resets the cache each pass iteration. No functional change — only a compile-time performance improvement for large functions.Benmark data
For the test case in #7319 (comment)
Main head:
time ./build/bin/wasm-opt --code-folding --enable-bulk-memory --enable-multivalue --enable-reference-types --enable-gc --enable-tail-call --enable-exception-handling -o /dev/null ./test3.wasm real 7m53.093s user 8m28.756s sys 0m1.100sThis PR:
time ./build/bin/wasm-opt --code-folding --enable-bulk-memory --enable-multivalue --enable-reference-types --enable-gc --enable-tail-call --enable-exception-handling -o /dev/null ./test3.wasm real 4m25.416s user 5m1.491s sys 0m1.829s