This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Improve inling in ImmutableArray<T>.Builder #28177
Merged
stephentoub
merged 1 commit into
dotnet:master
from
svick:immutablearray-builder-inlining
Mar 18, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can optimize
Addeven further when you split it in a fast- and cold-path. LikeNote that
Addhas to be attributed withAggressiveInlining, because -- interestingly though less asm-size -- the JIT won't inline otherwise.This also safes the bounds-check in the fast-path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gfoidl That's a significant increase in complexity. Do you have something that shows that it's actually sufficiently faster to warrant that?
I made a quick benchmark and it seems your code is actually slower (
SimpleAddis the original code,TweakedAddis code with my change,SplitAddis your change):There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List.Add, Stack.Push and similar classes use this pattern and there it is faster. My suggestion is based on that experience.
When I run your benchmark the results look a bit different.
Linux:
Windows:
Can you please re-check with your benchmark?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gfoidl I'm still getting
SplitAddas slower on my machine:It could be caused by the different CPU, or maybe something else. Though even with your numbers, it's only 10 % improvement, so I'm not sure it's worth that much additional complexity.
Because of that, I'm not going to change my PR to include your changes. Instead, you could open your own PR.