Repository navigation
Avoid quadratic VB CodeDOM overload scans - #136090
Open
marius-bughiu wants to merge 2 commits into
Open
marius-bughiu wants to merge 2 commits into
marius-bughiu wants to merge 2 commits into
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 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 |
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-codedom |
This was referenced Nov 23, 2026
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.
VBCodeProvider scans every member of a type for each method to decide whether to emit
Overloads. A generated type with thousands of uniquely named methods therefore performs quadratic name matching even though none of those methods is overloaded. This came from profiling workflow-generated VB support code; the measurements below use standalone synthetic CodeDOM graphs with unique method names.Cache an ordinal-ignore-case overload index for types with more than 32 members. Keep the scan for smaller types, where index setup costs more. The index distinguishes repeated references from distinct same-name methods, excludes constructors and explicit interface implementations, and observes the explicit
Overloadedflag directly.Track changes to indexed method identities and member collections so provider reuse and lazy
Populatecallbacks retain existing behavior. Explicit-implementation renames do not invalidate the index because those methods are excluded; this also avoids rebuilding on the generator's own temporary renames. Tracking reuses an existing method-state bit. Weak type keys and member positions avoid retaining discarded types or removed methods, without allocating a weak reference for every method.Performance
Baseline is
91b63bf88257142d4ffcb61d1728659ee0a51064; candidate is this change alone. Isolated and cumulative before/after/delta are identical for this independent PR: there are no prerequisite performance patches in either build. Both use the same source-built Release runtime; only the System.CodeDom implementation differs.Windows 11 x64, Intel Core i7-14700; BenchmarkDotNet 0.16.0-preview.2. Each benchmark child verified its loaded DLL SHA256 and reported the source-built .NET 12.0.0 development runtime. The SDK/benchmark TFM is net11.0; that label is not the execution runtime. Each arm/case used one fresh process, 3 warmup iterations, 10 measured iterations and a 250 ms target iteration time. These are local measurements, not cross-machine confidence estimates or end-to-end compiler speedups.
FreshGraphAndGenerateincludes graph construction, a new provider, generation and materializing the output string.+ explicitadds one distinct explicit-interface implementation after each public method, doubling total method count. All public method names are unique; repeated expressions are not required for the optimization.Managed allocation for those same operations:
The full tables below include small graphs, unchanged provider reuse, rename invalidation, and graph construction alone. For large types, generation with a new provider allocates 2.33-8.37% more; reusing a provider allocates 2.64-7.36% less because indexed lookup also avoids a collection enumerator per method. Graph construction adds 8 bytes per graph in the direct allocation check; the method tracking bit adds no field. A new provider also adds 8 bytes in the small-type benchmarks.
Small-case mean times range from -9.43% to +7.93% in the main run; there is no claim of a uniform small-type speedup. The separate 32-public-method cutoff case is 5.43% slower, an observed increase of 0.72 us. All results, including increases, are retained below. The process-wide mutation epoch can conservatively rebuild unrelated indexes after an indexed graph changes. Name strings and dictionary capacity remain until rebuild or type collection.
Seconds are rounded by magnitude; sub-millisecond values also show microseconds so rounding does not hide small-case differences. MB/GB use decimal units. Deltas use unrounded values.
All 40 isolated and cumulative timing comparisons
All 40 isolated and cumulative allocation comparisons
Separate cutoff check: 16, 32 and 64 public methods
These 12 jobs used the same final binaries and settings. They are a separate run, not pooled with the main matrix. The cutoff counts all members, including explicit implementations.
Validation
build.cmd clr+libs -rc Release -lc Release /m:1 /nr:false /p:UseSharedCompilation=false /p:ImportDirectoryPackagesProps=falsepassed. It reported 3 existing NU1902 package warnings..dotnet/dotnet.exe build src/libraries/System.CodeDom/tests/System.CodeDom.Tests.csproj -c Release /t:Test /m:1 /nr:false /p:UseSharedCompilation=false /p:ImportDirectoryPackagesProps=false /p:RuntimeConfiguration=Release /p:RunAnalyzersInBuild=true.Reproduce the measurements
Build the baseline runtime/testhost in Release, preserve it, then build this library change in Release and copy the exact implementation DLL beside the candidate
corerun. Keep both runtime directories otherwise identical. This is an out-of-shared-framework library, so the implementation DLL must be placed beside eachcorerun; the benchmark rejects any other loaded DLL hash.Create the following project in a fresh directory outside the runtime checkout. Put the baseline implementation at
reference/System.CodeDom.dll, fill inplan.json, setCODEDOM_BENCH_PLANto its absolute path, and rundotnet run -c Release -- --filter '*'. The benchmark exports full JSON statistics including confidence intervals and managed allocations. For the cutoff run replace both1, 10, 1000, 5000lists with16, 32, 64and filter*FreshGraphAndGenerate*. The--verifymode is output verification only; its un-warmed timings are not used in these performance tables.Benchmark.csproj
plan.json template
{ "readyForBenchmarks": true, "dotnet": "<absolute path to the repository SDK dotnet.exe>", "hosts": [ { "name": "Baseline", "coreRun": "<absolute path to baseline corerun.exe>", "codeDomSha256": "<SHA256 of baseline System.CodeDom.dll>" }, { "name": "Candidate", "coreRun": "<absolute path to candidate corerun.exe>", "codeDomSha256": "<SHA256 of candidate System.CodeDom.dll>" } ] }Program.cs — exact main-matrix harness
Note
This contribution was prepared with AI assistance.