-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Reflection
Milestone
Description
Background and motivation
Today, getting assembly simple name is done via assembly.GetName().Name. This does more work than necessary, like GetCodeBase, GetPublicKey, GetVersion, and allocating AssemblyName instance. In a hot code path, this can be problematic.
API Proposal
namespace System.Reflection;
public abstract partial class Assembly
{
+ public virtual string GetSimpleName() => GetName().Name;
}
internal sealed partial class RuntimeAssembly : Assembly
{
- internal string GetSimpleName()
+ public override string GetSimpleName()
{
RuntimeAssembly runtimeAssembly = this;
string? name = null;
GetSimpleName(new QCallAssembly(ref runtimeAssembly), new StringHandleOnStack(ref name));
return name!;
}
}
internal class DelegatingAssembly : Assembly
{
+ public override string GetSimpleName() => UnderlyingAssembly.GetSimpleName();
}
internal sealed partial class RuntimeAssemblyBuilder : AssemblyBuilder
{
+ public override string GetSimpleName() => InternalAssembly.GetSimpleName();
}
public sealed class PersistedAssemblyBuilder : AssemblyBuilder
{
+ public override string GetSimpleName() => _assemblyName.Name;
}API Usage
Example:
_ = typeof(MyType).Assembly.GetSimpleName();
// Instead of:
_ = typeof(MyType).Assembly.GetName().Name;Alternative Designs
Do nothing, and callers who have perf issues can introduce caching themselves.
The perf issue is more likely to be "querying the same assembly/assemblies over and over again" and not "querying too many different assemblies".
This was motivated by the perf investigations found in microsoft/vstest#15259 though.
Risks
No response
TiltonJH
Metadata
Metadata
Assignees
Labels
api-suggestionEarly API idea and discussion, it is NOT ready for implementationEarly API idea and discussion, it is NOT ready for implementationarea-System.Reflection