Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic generic dictionary expansion feature #32270

Merged
merged 11 commits into from
Feb 25, 2020

Conversation

fadimounir
Copy link
Contributor

@fadimounir fadimounir commented Feb 14, 2020

TODO:

These changes introduce dynamic size expansion for generic dictionary layouts when we run out of slots.
The original implementation allowed for an expansion, but using a linked list structure, which made it
impossible to use fast lookup slots once we're out of slots in the first bucket.

This new implementation allows for the usage of fast lookup slots always, for all generic lookups.

This also removes the constraint we had on R2R, where we disabled the usage of fast slots all-together.

NOTE:
This is a much simpler implementation than the original commit which got reverted due to failures related to collectible assemblies (dotnet/coreclr#26262). The difference between these changes and the original ones is that dictionary expansion for types and methods is now done lazily, on-demand, whenever we attempt to read a value beyond the size of a given dictionary. This makes uses of the newly added JIT support from #31957. The bug with collectible assemblies have been also fixed, and I added a test to cover various interesting aspects of the feature.

BONUS:
Part of these changes is some cleanup work to really simplify the R2R dictionary access stubs. These stubs are now much more compact with fewer instructions and better registry usage (many #ifdef UNIX_AMD64_ABI blocks removed from the amd64 stub)

cc @dotnet/crossgen-contrib

src/coreclr/src/inc/corinfo.h Show resolved Hide resolved
src/coreclr/src/inc/corinfo.h Show resolved Hide resolved
src/coreclr/src/inc/corinfo.h Show resolved Hide resolved
src/coreclr/src/jit/compiler.h Outdated Show resolved Hide resolved
src/coreclr/src/inc/corinfo.h Outdated Show resolved Hide resolved
src/coreclr/src/vm/genmeth.cpp Outdated Show resolved Hide resolved
src/coreclr/src/vm/methodtable.cpp Outdated Show resolved Hide resolved
@jkotas
Copy link
Member

jkotas commented Feb 14, 2020

Overall, I like this much better than the original version. Thanks!

@fadimounir
Copy link
Contributor Author

Couple of interesting benchmark numbers I tried:

  • Roslyn compiler, compiling Roslyn source code: 1~2% performance gain.
  • NewtonSoft serialization benchmark (found something on the web): 4% performance gain.

src/coreclr/src/vm/generics.cpp Outdated Show resolved Hide resolved
src/coreclr/src/vm/generics.cpp Outdated Show resolved Hide resolved
src/coreclr/src/vm/generics.cpp Outdated Show resolved Hide resolved
src/coreclr/src/vm/genericdict.cpp Outdated Show resolved Hide resolved
src/coreclr/src/vm/genericdict.cpp Outdated Show resolved Hide resolved
src/coreclr/src/vm/jitinterface.cpp Show resolved Hide resolved
src/coreclr/src/vm/method.hpp Outdated Show resolved Hide resolved
src/coreclr/src/vm/methodtablebuilder.cpp Outdated Show resolved Hide resolved
Fadi Hanna added 9 commits February 24, 2020 11:38
1) Separate dictionary layout expansion from dictionary expansions on types and methods
2) Dictionary expansions on types and methods done on-demand, after size checks by codegen (uses new JIT feature)
3) Update dependency tracking to only track derived types of base types with dictionaries
4) Update the R2R dictionary access stubs to perform size checks (and major cleanup there)
5) Fix loader allocator issue with the dependency tracking (bug in original implementation)
6) Add unit test
7) Update documentation
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@fadimounir fadimounir merged commit 7182559 into dotnet:master Feb 25, 2020
fadimounir pushed a commit to fadimounir/runtime that referenced this pull request Mar 6, 2020
fadimounir pushed a commit that referenced this pull request Mar 7, 2020
fadimounir pushed a commit to fadimounir/runtime that referenced this pull request Mar 7, 2020
jkotas pushed a commit that referenced this pull request Mar 7, 2020
jkotas added a commit that referenced this pull request Mar 9, 2020
…#33343)

* Revert "Revert "Dynamic generic dictionary expansion feature (#32270)" (#33310)"

This reverts commit dca3429.

* Fix race condition in dynamic dictionary resizing
@fadimounir fadimounir deleted the MakeDictionaryLayoutDynamic branch April 15, 2020 19:43
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants