Skip to content

[Wasm] Experimentally disable loop cloning and unrolling - #136640

Draft
adamperlin wants to merge 1 commit into
dotnet:mainfrom
adamperlin:adamperlin-wasm-loop-optimizations
Draft

adamperlin wants to merge 1 commit into
dotnet:mainfrom
adamperlin:adamperlin-wasm-loop-optimizations

Conversation

@adamperlin

@adamperlin adamperlin commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Experimentally skip loop cloning and unrolling for TARGET_WASM in all build configurations; other targets are unchanged.

Tradeoff: the 15 selected loop benchmarks were 1.69% slower (unweighted geometric mean), including SameIndex2 +12.20% and LLoops +8.97%, for these size reductions:

Output Before (bytes) Disabled (bytes) Reduction
Benchmark module, Wasm R2R 108,139 106,906 -1,233 (-1.14%)
SuperPMI libraries, matched contexts 35,043,653 34,909,538 -134,115 (-0.383%)
SuperPMI CoreLib, matched contexts 7,532,635 7,488,346 -44,289 (-0.588%)
Full benchmark numbers and measurement setup

Benchmark timings and Wasm size reductions

Positive time change means slower with both optimizations disabled. Times are per operation.

Benchmark Before (ns) Disabled (ns) Time change
ArrayDeAbstraction.foreach_static_array_via_interface 12,992.12 13,558.20 +4.36%
ArrayDeAbstraction.foreach_member_array 216.91 215.52 -0.64%
ArrayDeAbstraction.sum_static_array_via_local 73,301.41 75,367.23 +2.82%
Benchstone.BenchF.Adams.Test 1,116.80 1,092.91 -2.14%
Benchstone.BenchF.LLoops.Test 768,114,272.41 837,049,486.21 +8.97%
Layout.SearchLoops.LoopReturn 85.93 86.53 +0.70%
Layout.SearchLoops.LoopGoto 86.77 85.91 -0.99%
Span.IndexerBench.CoveredIndex2 1,008.07 1,042.70 +3.44%
Span.IndexerBench.WriteViaIndexer2 752.85 755.57 +0.36%
Span.IndexerBench.Ref 660.72 657.07 -0.55%
Span.IndexerBench.Indexer1 664.99 661.34 -0.55%
Span.IndexerBench.Indexer4 7,062.95 7,091.35 +0.40%
Span.IndexerBench.SameIndex1 928.77 944.28 +1.67%
Span.IndexerBench.SameIndex2 849.73 953.36 +12.20%
Span.IndexerBench.KnownSizeCtor2 689.40 665.46 -3.47%

Checked Wasm JITs at 35d5d14d206; unchanged benchmark sources from dotnet/performance 8588cdaa, linked into a focused BenchmarkDotNet harness. Release IL, per-assembly CoreCLR/Wasm ReadyToRun, Node.js 26.13.0; two launches, three warmups and 15 measured iterations per launch; span length 1,024. Both variants used the same private SDK overlay/native runtime, not a fully rebuilt SDK/workload cohort. Shared Hyper-V VM; small timing differences may be noise.

SameIndex2 retains an in-loop bounds check without cloning (372 to 266 code bytes). KnownSizeCtor2's helper had identical single-method codegen, so its measured speedup is not a direct codegen improvement. Cloning and unrolling were measured together.

SuperPMI compared 90,210/91,104 library contexts and 28,200/29,068 cached CoreLib contexts; missing recorded data excluded 894 and 868 respectively, with no other compilation failures. Total modeled PerfScore increased 0.401% and 0.979%; this is not measured execution time.

Validation: .\build.cmd clr.wasmjit -rc Checked passed; all 15 benchmark cases completed on both variants; identical-JIT SuperPMI control had no diffs in the 969 changed library contexts.

Note

PR description and analysis generated with GitHub Copilot.

Experiment with the Wasm code-size and loop-throughput tradeoff; leave other targets unchanged.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: 1c35665e-3fd9-4953-99e6-1beb765e7732
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 29, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@EgorBo

EgorBo commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

I think loop clonning is very important for bound check removal, I doubt only a handful benchmarks are affected by it. Perhaps, we should make it more conservative for optimize-for-size instead? cc @AndyAyersMS

Loop unrolling presumed to be a rare thing.

@adamperlin

adamperlin commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

I think loop clonning is very important for bound check removal, I doubt only a handful benchmarks are affected by it. Perhaps, we should make it more conservative for optimize-for-size instead? cc @AndyAyersMS

Loop unrolling presumed to be a rare thing.

That makes a lot of sense. I'll switch this to draft as this was mostly intended just as an experiment to see what the size impact is.

@adamperlin
adamperlin marked this pull request as draft October 30, 2026 17:15

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

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants