-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Optimise GetCustomAttribute(s) #45121
Conversation
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
Is this fixing #44713 ? |
I don't understand the context for this PR. What is it attempting to optimize, and how does it accomplish the optimization? |
Calling |
Ish; though that's Will add the rest of |
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs
Outdated
Show resolved
Hide resolved
e37b530
to
bde935e
Compare
src/coreclr/src/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
Outdated
Show resolved
Hide resolved
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
Outdated
Show resolved
Hide resolved
Working through some issues with ILLink... |
63c525f
to
3d80536
Compare
src/coreclr/src/System.Private.CoreLib/src/System/Reflection/CustomAttribute.cs
Outdated
Show resolved
Hide resolved
src/coreclr/src/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs
Outdated
Show resolved
Hide resolved
4ce94f9
to
0217d17
Compare
Need to investigate why Meanwhile some results:
|
|
Was an infinite loop from not using the updated variable. Will squash and rebase to resolve conflict |
695a964
to
fbab0df
Compare
@benaadams By frightening, did you mean you could use help resolving them? Or did @ViktorHofer's comment address your concerns? Thanks! |
@benaadams Would you like help resolving the conflicts, or will you be able to? Thanks! |
@jeffhandley can't currently build anything using .NET6.0 in VS dotnet/sdk#17461 |
@benaadams I worked through the conflicts:
I pushed all of this to a branch on my fork; you can see it here. I've run the build and Reflection unit tests locally, and they're passing. If you'd like, I could force push this into your fork on this branch. Just let me know. |
Please do 😀 |
a974b26
to
57e52fa
Compare
Force-pushed. Your unmodified branch is also pushed to my fork in case we need to reference the original for some reason. I'll plan to delete that after we merge this PR. |
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.
LGTM, but I'd like a re-review from either @jkotas or @steveharter before we merge it.
@@ -37,6 +37,21 @@ public virtual bool IsDefined(Type attributeType, bool inherit) | |||
public virtual IEnumerable<CustomAttributeData> CustomAttributes => GetCustomAttributesData(); | |||
public virtual IList<CustomAttributeData> GetCustomAttributesData() { throw NotImplemented.ByDesign; } | |||
|
|||
internal virtual Attribute? GetCustomAttribute(Type attributeType, bool inherit) |
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 am not fan of all these new internal methods on abstract base types.
This change is regressing handling of non-CLS compliant attributes. using System;
using System.Reflection;
using System.Reflection.Emit;
public class MyAttribute
{
}
class Program
{
static void Main(string[] args)
{
var ab = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("MyAssembly"), AssemblyBuilderAccess.Run);
var mb = ab.DefineDynamicModule("MyModule");
var tb = mb.DefineType("MyType");
tb.SetCustomAttribute(typeof(MyAttribute).GetConstructor(new Type[0]), new byte[0]);
var t = tb.CreateType();
foreach (var a in t.GetCustomAttributes(true)) Console.WriteLine(a.ToString());
}
} This succeeds before this change, but fails with |
I have been going through this change for a while and I find it difficult to review. It is really multiple independent changes together:
I think it would be more productive to submit these changes one at a time in individual PRs. They would be much easier to review and merge with confidence. |
I do like the idea behind this set of changes. It would be nice to get it in. |
I agree with Jan on this. I know you've been putting considerable care into this PR and it's frustrating to have to split this, but it seems like the fastest way forward. |
I have peeled off a subset of this change into #53152 |
I've converted this to a draft since per the comments about splitting it up into separate PRs and #53152 already being addressed. @benaadams -- let us know if you plan to peel off other increments from this or if this should go onto our team's backlog. Thanks! |
Draft Pull Request was automatically closed for inactivity. Please let us know if you'd like to reopen it. |
For
GetCustomAttribute
brings allocations down to 25% and down to 3% for #44713 (to just the requested attribute); with a performance improvement of 25% and 56% for #44713For
PropertyInfo
,Type
,ConstructorInfo
,MethodInfo
,FieldInfo
,EventInfo
For
GetCustomAttributes
andGetCustomAttributes(Type)
it halves allocations to just array + attributeResolves #44713