-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add a comment explaining why not to switch ImmutableArray.Empty to Array.Empty #32365
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
Conversation
src/libraries/System.Collections.Immutable/tests/ImmutableArrayTest.cs
Outdated
Show resolved
Hide resolved
|
This will introduce performance regression when Empty is called from generic code and T is reference type. The current JIT has inlining limitations for cases like these. @davidwrighton is trying to fix them in #31833 . Once it is fixed, it should be ok to make this change - but only for netcoreapp5.0+ builds of this library. |
|
Actually, scratch my comment. I have not noticed that Still, it is not obvious whether this is an improvement. It saves allocation of one tiny object on GC heap, but introduces more code. It is likely a net regression when looking at the total memory consumption. |
|
The disabled Looking at the IL, the And from the looks of it, even the JIT is smaller. |
|
Small generic types and methods have non-trivial overhead in the runtime datastructures that is easy to miss. Here is a micro-benchmark that demonstrates the impact of this PR https://gist.github.com/jkotas/6b5d2c7088b2a8d8c6332b2c7d74ce74#file-arraywrapper Without |
|
If you agree, I think this PR can be closed. |
|
@jkotas Thanks for that benchmark, that's really interesting info. Instead of closing, can I repurpose the PR to add a comment on that behaviour so this won't be PR'd again in the future? |
|
Yep, adding a comment on this would be great! |
c1d6ec1 to
2f13ac4
Compare
|
Now it's all a single comment added. |
jkotas
left a comment
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.
Thanks
No description provided.