-
-
Notifications
You must be signed in to change notification settings - Fork 776
feat: use private static fields to store constant typeParameters where possible
#1606
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
private static fields to store constant typeParameters where possibleprivate static fields to store constant typeParameters & genericTypes where possible
private static fields to store constant typeParameters & genericTypes where possibleprivate static fields to store constant typeParameters where possible
c5b222b to
680f3b9
Compare
|
Seems legit, @clairernovotny? |
680f3b9 to
638bef2
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1606 +/- ##
=======================================
Coverage 87.81% 87.81%
=======================================
Files 33 33
Lines 2347 2347
Branches 294 294
=======================================
Hits 2061 2061
Misses 207 207
Partials 79 79 ☔ View full report in Codecov by Sentry. |
1e659da to
33f669b
Compare
8173af0 to
d912119
Compare
d912119 to
a54d24e
Compare
|
@ChrisPulman Any objections to this PR? |
I am currently in India, but I will check it this evening and merge it if it's fitting to our requirements, thank you. |
|
All looks good, thank you Tim |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Modify source generator to use
private static readonlyfields to store thetypeParameterarrays, saving the allocations for each request.Array.Emptyis used - feat: generate code that usesArray.Emptywhere possible #1599private staticfields are generated beside its respective method, this could be moved to the start of the class if requested.HashSetof each member in scope to accidental name collisions. Fields will have names like_typeParameters3incrementing for each field generated.Uses nullable coalescing assignment if one of the method parameters uses type arguments. This is done as we may not be able to access it from outside the method scope making the array initialization invalid.It should be safe to initialize and set the static arrays in multithreaded contexts as setting references are thread safe in C#.Edit:
typeof(T)will be different for each usage of T so it isn't possible to have a reusable_genericTypearray. This can also cause issues for_typeParameter.GenerateTypeParameterExpressionensures that each parameter doesn't contain a generic type parameter, falling back to the current solution if it detects one.See #1598