Repository navigation
Conversation
|
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: @dotnet/area-system-collections |
Member
|
Duplicate of #137582 |
This was referenced Nov 15, 2026
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.
For batches of 16 collections with 65,536 items each, mean
Clear()time fell by 73.62-80.76% forintand 92.68-93.39% for a 64-byte value type in two BenchmarkDotNet comparisons.This copies the behavior already used by
HashSet<T>.Remove()and follows #136605.Clear()now sets the count to zero and resets the buckets and free list without clearing the entry array whenTcontains no object references. New items overwrite old entries before use. Types that contain references, including structs, are still cleared.Performance
Selected
ClearBench<T>.ClearOnlyresults for 16 collections per batch. Setup and validation are outside timing. Times are microseconds (us) per batch, shown as mean +/- sample standard deviation for each process.intintWideWideBenchmarkDotNet
0.16.0-preview.2,InProcessEmitToolchain, verified High process priority. Each version ran in two fresh processes. Clear-only used 10 warmups and 100 measurements. Clear-and-refill used 8 warmups and 30 measurements targeting 500 ms each.Windows 11 Pro x64 (build 26200), Ryzen 9 5950X, Release
.NET 12.0.0-dev. ReadyToRun and tiered compilation were disabled; concurrent workstation GC was enabled.Clear-only iterations were shorter than BenchmarkDotNet recommends, and some results had multiple timing clusters. All samples are included. These comparisons do not establish statistical significance. One 65,536-item
RefValueclear-and-refill run was 97.9% slower. Three separate process pairs running only this case did not reproduce that increase. The cause remains unknown.Validation
System.Collections.Testsbuilt fromc170eff79a4passed 33,973 tests. Tests ran on the isolated benchmark runtime image with the matching collection implementation. No failures.ICollection_Generic_Clearchecks the count after clear, andICollection_Generic_Add_AfterCallingClearchecks the count after refill.HashSet_Generic_TrimExcess_AfterClearingAndAddingSomeElementsBackchecks the count after clear, trimming, and partial refill.Clear_AfterRemoval_DoesNotExposeOldItemschecks exact contents and collision lookups after partial refill without trimming. It verifies that old items cannot be found.git diff --checkpassed.Full benchmark results and setup
Widecontains eightlongfields (64 bytes), compares all fields, and hashes the first.RefValuecontains alongand an object reference. Input values are created once and reused.Benchmark baseline
8ac60f59b95, with this PR's collection implementation applied for the patched runs. OnlySystem.Private.CoreLib.dlldiffers between the baseline and patched runtime images. Native runtime files are identical.Baseline/patched order was randomized with seed 136605. No outliers were removed. Clear-only uses one invocation per measurement and checks that all collections are empty afterward.
CycleBench<T>.ClearAndRefillclears and refills one collection per invocation. Refill is timed; existing storage and input values are reused. Each case recorded at least 10 seconds of measured work. Cleanup checks the final count.Clear-only batches of sixteen collections, in microseconds.
intintWideWideRefValueRefValueintintWideWideRefValueRefValueSustained clear-and-refill cycles, in microseconds.
intintWideWideRefValueRefValueintintWideWideRefValueRefValueHigher patched means in at least one process:
RefValueat 1,024 items (Clear-only, up to 0.6%),intat 1,024 items (clear-and-refill, up to 6.0%),RefValueat 65,536 items (clear-and-refill, up to 97.9%).HashSet reference-containing check
In the main matrix,
CycleBench<RefValue>.ClearAndRefillat 65,536 items had a 97.9% higher patched mean in launch 2; launch 1 was 1.7% lower. A separate check ran this case alone in three fresh process pairs, without the precedingintandWidecases. It retained eight warmups, thirty measured iterations, a 500 ms target, High priority, and all observations. Baseline/patched order used seed 136606.Values are mean +/- sample SD per process. These isolated comparisons did not reproduce the 97.9% increase, but had large variation within each process. The original observation remains unexplained; the separate check does not rule it out.
Untimed setup diagnostics found identical hash distributions in all six confirmation processes: capacity 75,431, occupied buckets 43,859, maximum bucket load 7, and 28,304 colliding pairs. Those diagnostics were not collected in the original matrix and therefore cannot explain its anomaly.
Timed methods
Note
The implementation, tests, and pull request description were prepared with OpenAI Codex (Fable). I used Tedd.DotNetLab for the performance investigation. I have manually reviewed and checked everything.