Repository navigation
[ILLink] Avoid exponential walks over deep interface hierarchies - #136767
Open
ramezgerges wants to merge 1 commit into
Open
ramezgerges wants to merge 1 commit into
ramezgerges wants to merge 1 commit into
Conversation
An interface's metadata lists every interface it inherits, so in a deep chain the same interface is reachable through exponentially many paths. Three walks followed all of them: - TypeMapInfo.FindAndAddDefaultInterfaceImplementations, when looking for a default implementation of an interface method; - TypeMapInfo.AddRecursiveInterfaces, when collecting a type's recursive interfaces; - MarkStep.MarkBaseMethods, when marking the bases of a base method that was already marked (ProcessMethod marks those bases itself). Each now visits an interface (or already-marked base method) once. Trimming an app with a 29-deep [GeneratedComInterface] chain, such as the WebView2Aot interop library, no longer hangs. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 of 2 tasks
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/illink |
This branch has not been deployed
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.
Fixes #136766
An interface's metadata lists every interface it inherits, so in a deep chain the same interface is reachable through exponentially many paths. Three walks followed every one of them:
TypeMapInfo.FindAndAddDefaultInterfaceImplementationsnow carries a visited set. Each interface is searched once per lookup. Whether an interface provides the default implementation, or has its bases searched, depends only on the interface and the method, not on the path that reached it.TypeMapInfo.AddRecursiveInterfacesnow carries an expanded set (sameTypeReferenceEqualityCompareras the result list, so generic instantiations stay distinct). An interface's first expansion already adds everything below it, with the first chain to each, which is the one the list keeps.MarkStep.MarkBaseMethodsonly recurses into a base method it newly marked. An already-marked base gets its own bases marked whenProcessMethodprocesses it.The real-world trigger is COM interop generated by
[GeneratedComInterface]for versioned interfaces. For example, WebView2Aot'sICoreWebView2_29 : ICoreWebView2_28, …makes every trimmed publish of an app that references it hang.Test
Inheritance.Interfaces.RecursiveInterfaces.DeepInterfaceHierarchy: a 28-deep chain plus an interface deriving from the top one. Mapping the assembly's types is enough to hit all of it. It passes in about 0.5 s with this change. Without it, theInheritance.Interfacessuite hit a 3-minute--blame-hang-timeout.Validation
build.cmd -s tools.illink+tools.illinktests -c Release -restore -build -test:Mono.Linker.Tests: 1307 passed, 0 failed, 30 skipped.ILLink.Tasks.Tests: 296 passed.ILLink.RoslynAnalyzer.Testscouldn't run locally: every case fails withDirectoryNotFoundExceptionforartifacts/bin/ILLink.RoslynAnalyzer.Tests/Release/net11.0/live-ref-pack, which a tools-only build doesn't produce.[GeneratedComInterface]chain with 10 methods per level: depth 20 > 240 s → 3.5 s, depth 29 hang → 5.4 s;WebView2.dllrooted: > 300 s → 9 s.