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

Optimize ToArray for non-empty enumerables - #2668

Closed
jamesqo wants to merge 2 commits into
dotnet:masterfrom
jamesqo:buf
Closed

Optimize ToArray for non-empty enumerables#2668
jamesqo wants to merge 2 commits into
dotnet:masterfrom
jamesqo:buf

Conversation

@jamesqo

@jamesqo jamesqo commented Aug 7, 2015

Copy link
Copy Markdown
Contributor

Separated from PR #2318. This does not negatively impact empty collections, and behavior for Buffer<T>.ToArray() shouldn't change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With this change, all of the accesses in this method are now field accesses rather than local accesses. You've verified that doesn't harm the generated assembly?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 here.
Keeping items and count as locals until the copying is done can be beneficial, so I'd preserve that. The change removes one null check (that seems to be very predictable), so perf benefit of that might be relatively small and I wonder if introducing field accesses may actually make things slower.

  • can we keep items/count as locals until done copying?
  • what speedup are we looking at here overall?

@stephentoub

Copy link
Copy Markdown
Member

cc: @VSadov

@jamesqo

jamesqo commented Aug 18, 2015

Copy link
Copy Markdown
Contributor Author

Closed because of dupe @ #2871.

@jamesqo jamesqo closed this Aug 18, 2015
JonHanna added a commit to JonHanna/corefx that referenced this pull request Aug 18, 2015
…e use of locals.

One use of goto, but perhaps worth the velociraptor risk.
@jamesqo
jamesqo deleted the buf branch September 20, 2015 04:36
@karelz karelz modified the milestone: 1.0.0-rtm Dec 3, 2016
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