Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

stephentoub
Copy link
Member

Small improvement to List.Add's code quality. In a microbenchmark that adds lots of integers to a list (without needing to grow), this improves throughput by ~10%.

cc: @jkotas

Small improvement to List.Add's code quality.  In a microbenchmark that adds lots of integers to a list (without needing to grow), this improves throughput by ~10%.

// Separated out of List.Add to improve its code quality
[MethodImpl(MethodImplOptions.NoInlining)]
private void GrowCapacityForAdd()
Copy link
Member

Choose a reason for hiding this comment

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

Caching size in a local makes sense, but I would not expect that factoring out EnsureCapacity(_size+1) to separate method to help anything. Is GrowCapacityForAdd really needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

On the machine I was using before, it actually did make a measurable difference, and it resulted in different asm (beyond the expected changes related to args). I'm now on a different machine, though, and I'm not able to repro the perf difference. I'll take another look at it over the weekend or on Monday.

Copy link
Member

Choose a reason for hiding this comment

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

I tried this; but NoIining was getting ignored as function was coming up as [below ALWAYS_INLINE size] couldn't determine if it was new behaviour or always like it. Was also doing it before the StackCrawl change, where caller would get inlined regardless if it was extremely simple.

Copy link
Member

Choose a reason for hiding this comment

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

where caller would get inlined regardless if it was extremely simple.

This sounds like a bug that we should fix if you still see it. NoInlining should always mean NoInlining, no exceptions.

@stephentoub
Copy link
Member Author

I'm going to close this; I've tried on a few machines now, and in some cases the new version is faster, in others it's slower.

@stephentoub stephentoub closed this Feb 4, 2017
@stephentoub stephentoub deleted the list_add branch February 4, 2017 13:33
@stephentoub stephentoub mentioned this pull request Feb 12, 2017
@karelz karelz modified the milestone: 2.0.0 Aug 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants