Skip to content

ILLink takes exponential time on deep interface hierarchies #136766

Description

@ramezgerges

Description

ILLink takes time exponential in the depth of an interface hierarchy. A trimmed publish of code with a deep interface chain runs for minutes, or never finishes.

Interface metadata lists every interface an interface inherits, not only its direct base. In a chain I1, I2 : I1, …, In : In-1, the interface In therefore lists all of I1…In-1, and each of those lists its own ancestors. Three walks follow every path through those lists without remembering what they already visited:

  • TypeMapInfo.FindAndAddDefaultInterfaceImplementations (looking for a default implementation of each interface method);
  • TypeMapInfo.GetRecursiveInterfaceImplementations → AddRecursiveInterfaces;
  • MarkStep.MarkBaseMethods, which recurses into the bases of a base method even when that base is already marked (ProcessMethod marks those bases itself).

Real-world trigger: COM interop generated by [GeneratedComInterface] for versioned interfaces. For example, WebView2Aot has ICoreWebView2_29 : ICoreWebView2_28, …, ICoreWebView2. Any app referencing it can't complete a trimmed publish. That's how we hit it in Uno Platform: unoplatform/uno#24618.

Reproduction Steps

dotnet new console -n DeepChain && cd DeepChain
# Generate a chain of 26 interfaces plus an interface deriving from the top one:
#   interface I1 { void M1(); }
#   interface I2 : I1 { void M2(); }
#   ...
#   interface I26 : I25 { void M26(); }
#   interface ILeaf : I26 { }
python -c "n=26; print('\n'.join([f'interface I{k}'+(f' : I{k-1}' if k>1 else '')+f' {{ void M{k}(); }}' for k in range(1,n+1)]+[f'interface ILeaf : I{n} {{ }}']))" > Chain.cs
dotnet publish -c Release -r win-x64 -p:PublishTrimmed=true

Expected behavior

The publish completes in seconds, in time roughly linear in the size of the hierarchy.

Actual behavior

"Optimizing assemblies for size" takes time exponential in the chain depth:

Chain depth dotnet publish -p:PublishTrimmed=true (SDK 11.0.100-preview.7)
22 13 s
26 92 s

Running ILLink directly on the same kind of assembly, rooted with -a <dll> all:

Chain depth ILLink 10.0.10 ILLink 11.0.0-rc.2
16 3 s —
20 4 s —
24 21 s —
[GeneratedComInterface] chain, depth 16, 10 methods per level 29 s 28 s
[GeneratedComInterface] chain, depth 20, 10 methods per level > 240 s (killed) > 240 s (killed)
WebView2.dll (WebView2Aot 1.5.0), depth 29 > 300 s (killed) —

A stuck process sits in TypeMapInfo.FindAndAddDefaultInterfaceImplementations (recursing on itself), under TypeMapInfo.MapType ← MarkStep.MarkMethodIfNeededByBaseMethod ← MarkStep.MarkType.

Regression?

Not determined. Reproduces with ILLink 10.0.10 and 11.0.0-rc.2.

Known Workarounds

Remove the assembly with the deep chain from the trimmer's inputs, or disable trimming.

Configuration

  • ILLink 10.0.10 (.NET SDK 10.0.302) and 11.0.0-rc.2.26504.105; dotnet publish with SDK 11.0.100-preview.7
  • Windows 11 x64. The walks are platform-independent; the original report is from Linux.

Other information

A fix that visits each interface (and each already-marked base method) once is in #136767. With it, the [GeneratedComInterface] depth-29 chain links in 5.4 s, WebView2.dll in 9 s, and the trimmed outputs are byte-identical to stock ILLink's wherever stock ILLink completes.

Activity

  1. added
    untriaged
    on Oct 31, 2026
  2. added
    area-Tools-ILLink
    on Oct 31, 2026
  3. dotnet-policy-service commented on Oct 31, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @agocke, @dotnet/illink
    See info in area-owners.md if you want to be subscribed.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Tools-ILLinkuntriaged

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions