Skip to content

Avoid delegate allocation in generic cycle detector#79842

Merged
MichalStrehovsky merged 1 commit intodotnet:mainfrom
MichalStrehovsky:cycledetect
Dec 22, 2022
Merged

Avoid delegate allocation in generic cycle detector#79842
MichalStrehovsky merged 1 commit intodotnet:mainfrom
MichalStrehovsky:cycledetect

Conversation

@MichalStrehovsky
Copy link
Member

Removes 1,000,000 (one million) allocations while compiling a hello world. We were allocating a delegate and a closure each time we saw a reference from something generic to something generic.

This replaces the delegate with a manual closure allocated on the stack. The number of stack allocated entries was chosen arbitrarily. The highest recursion we see in CoreLib is for 3 elements, so 4 includes a bit of a buffer.

Maybe it's a tiny bit less readable, but not that much.

Cc @dotnet/ilc-contrib

Removes 1,000,000 (one million) allocations while compiling a hello world. We were allocating a delegate and a closure each time we saw a reference from something generic to something generic.

This replaces the delegate with a manual closure allocated on the stack. The number of stack allocated entries was chosen arbitrarily. The highest recursion we see in CoreLib is for 3 elements, so 4 includes a bit of a buffer.

Maybe it's a tiny bit less readable, but not that much.
@ghost
Copy link

ghost commented Dec 20, 2022

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Removes 1,000,000 (one million) allocations while compiling a hello world. We were allocating a delegate and a closure each time we saw a reference from something generic to something generic.

This replaces the delegate with a manual closure allocated on the stack. The number of stack allocated entries was chosen arbitrarily. The highest recursion we see in CoreLib is for 3 elements, so 4 includes a bit of a buffer.

Maybe it's a tiny bit less readable, but not that much.

Cc @dotnet/ilc-contrib

Author: MichalStrehovsky
Assignees: MichalStrehovsky
Labels:

area-NativeAOT-coreclr

Milestone: -

Copy link
Contributor

@LakshanF LakshanF left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@MichalStrehovsky MichalStrehovsky merged commit e467a5f into dotnet:main Dec 22, 2022
@MichalStrehovsky MichalStrehovsky deleted the cycledetect branch December 22, 2022 23:26
@ghost ghost locked as resolved and limited conversation to collaborators Jan 22, 2023
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.

2 participants