-
Notifications
You must be signed in to change notification settings - Fork 420
Add identity method to reduce JIT-ing #880
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
Codecov Report
@@ Coverage Diff @@
## master #880 +/- ##
=======================================
Coverage 92.38% 92.39%
=======================================
Files 110 111 +1
Lines 3441 3443 +2
Branches 1020 1021 +1
=======================================
+ Hits 3179 3181 +2
Misses 200 200
Partials 62 62
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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.
I don't see the value in adding this because it's not improving anything. It's less ergonomic/succinct (or more verbose) than just a lambda (x => x
) and it's not removing duplication of any “methods” per the PR subject line. What's more, it doesn't work with anonymous types.
@viceroypenguin Thanks for the detailed explanation. I understand now the savings you're trying to make with this and it would have been great to have the justification in the initial description. I'll come back to you on this, hopefully before the week is over. |
My main concern was as a method group within a query where you're expecting to use var map =
Enumerable.Range(1, 10)
.Select(x => new { X = x, Y = x * 2 })
.ToDictionary(x => x.X, Identity); I was somewhat misled during my initial review by the explicit type annotations like |
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 for adding this. I think you missed another opportunity to use identity function in Split
?
Ah, right. Totally missed that. Amazing how powerful the typing system is sometimes. :) |
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, and nearly there! 🏁
Co-authored-by: Atif Aziz <code@raboof.com>
Currently, the C# compiler does not de-dupe methods, including identity methods, such as
x => x
. This means each instance ofx => x
is compiled as a separate method; and each method must be JIT to asm separately, and must be done so for each type separately.Adding an
Identity
method improves JIT significantly:Until .net7.0 + tiered PGO, these methods will not get inlined because they are accessed via delegate. This means they also take additional space in memory due to the translated code.