Repository navigation
Description
A small method with 10 sequential if (a[i] is { } t && ...) x = t; statements takes tens of seconds and gigabytes of memory to JIT. Almost all of that time is spent in Assertion prop.
Minimal Repro
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
public class Program
{
public static void Main()
{
var sw = Stopwatch.StartNew();
RuntimeHelpers.PrepareMethod(typeof(Program).GetMethod(nameof(Test))!.MethodHandle);
Console.WriteLine($"JIT time: {sw.ElapsedMilliseconds} ms");
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static int Test(string?[] a, int m)
{
string x = "abc";
if (a[0] is { } t0 && (m & 1) > 0 && (m & 2) > 0 && (m & 4) > 0 && (m & 8) > 0 && (m & 16) > 0 && (m & 32) > 0) x = t0;
if (a[1] is { } t1 && (m & 1) > 0 && (m & 2) > 0 && (m & 4) > 0 && (m & 8) > 0 && (m & 16) > 0 && (m & 32) > 0) x = t1;
if (a[2] is { } t2 && (m & 1) > 0 && (m & 2) > 0 && (m & 4) > 0 && (m & 8) > 0 && (m & 16) > 0 && (m & 32) > 0) x = t2;
if (a[3] is { } t3 && (m & 1) > 0 && (m & 2) > 0 && (m & 4) > 0 && (m & 8) > 0 && (m & 16) > 0 && (m & 32) > 0) x = t3;
if (a[4] is { } t4 && (m & 1) > 0 && (m & 2) > 0 && (m & 4) > 0 && (m & 8) > 0 && (m & 16) > 0 && (m & 32) > 0) x = t4;
if (a[5] is { } t5 && (m & 1) > 0 && (m & 2) > 0 && (m & 4) > 0 && (m & 8) > 0 && (m & 16) > 0 && (m & 32) > 0) x = t5;
if (a[6] is { } t6 && (m & 1) > 0 && (m & 2) > 0 && (m & 4) > 0 && (m & 8) > 0 && (m & 16) > 0 && (m & 32) > 0) x = t6;
if (a[7] is { } t7 && (m & 1) > 0 && (m & 2) > 0 && (m & 4) > 0 && (m & 8) > 0 && (m & 16) > 0 && (m & 32) > 0) x = t7;
if (a[8] is { } t8 && (m & 1) > 0 && (m & 2) > 0 && (m & 4) > 0 && (m & 8) > 0 && (m & 16) > 0 && (m & 32) > 0) x = t8;
if (a[9] is { } t9 && (m & 1) > 0 && (m & 2) > 0 && (m & 4) > 0 && (m & 8) > 0 && (m & 16) > 0 && (m & 32) > 0) x = t9;
return x.Length;
}
}Expected
The method compiles in a few milliseconds.
Actual
On main (Checked, windows-x64), JIT time: ~20000 ms and the peak working set is about 2.9 GB.
Regression?
Yes. .NET 8.0.31, 9.0.20 and 10.0.12 compile this in about 1 ms. .NET 11.0.0-rc.2.26467.112 takes about 10 s and 2.9 GB.
Notes
optAssertionVNIsNonNull walks PHIs recursively through optVisitReachingAssertions. The walk only has a depth limit of 10 and keeps no visited set. Each join has about 7 predecessors with the same PHI VN, so the walk visits about 7^10 nodes, and each visit allocates 2 arena BitVecs.
Possible fix: add a visited set, a memo, or a node budget for each query, and reuse the BitVec scratch.
This is the optAssertionVNIsNonNull counterpart of #133857, which covers optAssertionVNIsSubtype.
Activity
dotnet-policy-service commentedon Sep 22, 2026
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.
AndreasPK commentedon Oct 5, 2026
I've hit this bug in a project of mine where it caused a non-trivial overhead on startup.