You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just an experiment. I see FindValue way too often in various perf traces and considering that string is, probably, the most popular key type (among ref types), maybe we can special case it? It gives us:
We can inline the hash code function
We can inline the string compare function (when hash matches)
Maybe we can even intrinsify hashcode for known string literals?
Currently PGO can't devirtualize anything inside FindValue due to known limitations.
In my benchmarks this improves Lookup (indexer/TryGetValue) by 30%
usingBenchmarkDotNet.Attributes;usingBenchmarkDotNet.Running;BenchmarkSwitcher.FromAssembly(typeof(MyBench).Assembly).Run(args);publicclassMyBench{Dictionary<string,int>_d=Enumerable.Range(1000,1000).ToDictionary(i =>i.ToString(), i =>i);[Benchmark]publicintIndexer()=>_d["1500"];[Benchmark]publicboolTryGetValue()=>_d.TryGetValue("1500",out_);}
Maybe more fundamentally, can we do limited generic specialization for reference types? Or in contrast, can we use shared generic for value types with same size?
JIT shouldn't automatically do that without any instruction. Have the capability would be nice.
With the current shape we see +30% perf for lookup for the default case (when it's not yet switched to randomized hashing), but other types of comparers (e.g. OrdinalIgnoreCase or custom) will recieve a small penalty (type check for comparer) so not sure if it's worth duplicating code for them as well.
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 freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
3 participants
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.
Just an experiment. I see
FindValueway too often in various perf traces and considering that string is, probably, the most popular key type (among ref types), maybe we can special case it? It gives us:Currently PGO can't devirtualize anything inside FindValue due to known limitations.
In my benchmarks this improves Lookup (indexer/TryGetValue) by 30%