Skip to content

Conversation

@eduardo-vp
Copy link
Member

@eduardo-vp eduardo-vp commented Dec 19, 2025

Moved some APIs to UTF-8 when there was the chance to avoid some string allocations for at least some code paths.

Contributes to #122363.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR moves managed type system APIs from string-based operations to UTF-8 byte spans to reduce string allocations during compilation. The changes update core interfaces (IPrefixMangledType, IPrefixMangledMethod, IPrefixMangledSignature, MetadataType.GetNestedType) and their implementations to use ReadOnlySpan<byte> instead of string.

Key Changes

  • Interface signatures changed from string to ReadOnlySpan<byte> for name/prefix properties
  • GetNestedType methods now accept ReadOnlySpan<byte> parameters
  • String literals converted to UTF-8 literals (e.g., "Boxed" → `"Boxed"u8)
  • Switch statements replaced with if-else chains for span comparisons

Reviewed changes

Copilot reviewed 43 out of 43 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
IPrefixMangledType.cs Changed Prefix property from string to ReadOnlySpan
IPrefixMangledMethod.cs Changed Prefix property from string to ReadOnlySpan
IPrefixMangledSignature.cs Changed Prefix property from string to ReadOnlySpan
MetadataType.cs Changed GetNestedType parameter from string to ReadOnlySpan
CompilerTypeSystemContext.Mangling.cs Updated Prefix implementations to return UTF-8 literals
CompilerTypeSystemContext.InterfaceThunks.cs Added caching of UTF-8 prefix as byte array field
CompilerTypeSystemContext.BoxedTypes.cs Updated GetNestedType signature
CompilerTypeSystemContext.GeneratedAssembly.cs Updated GetNestedType signature
ReadyToRunCompilerContext.cs Changed GetNestedType call to use UTF-8 literal
Compilation.cs Changed GetKnownNestedType call to use UTF-8 literal
TypeRefTypeSystemType.cs Updated GetNestedType with UTF-8 parameter, converts to string for dictionary lookup
EcmaType.cs Updated GetNestedType to accept UTF-8, uses Append and GetString
EcmaModule.cs Updated type reference resolution to use UTF-8 with Append
TypeSystemHelpers.cs Changed GetFullName to return UTF-8, uses Append extension
SimpleArrayOfTRuntimeInterfacesAlgorithm.cs Changed static array to ReadOnlyMemory[] for UTF-8 storage
UnmanagedCallingConventions.cs Converted switch expression to if-else chain for UTF-8 comparisons
ComparerIntrinsics.cs Changed methods to accept UTF-8 parameters, uses Append for type name construction
NativeAotILProvider.cs Converted switch to if-else chain for UTF-8 name comparisons
Multiple *Mangling.cs files Updated Prefix implementations to return UTF-8 literals
Multiple type stub files Updated GetNestedType method signatures
CalliMarshallingMethodThunk.Mangling.cs Added UTF-8 prefix logic with Append call
HelperExtensions.cs Updated GetKnownNestedType signature
CustomAttributeTypeNameParser.cs Updated nested type lookup to convert to UTF-8
ProcessLinkerXmlBase.cs Updated nested type lookup to convert to UTF-8
Multiple partial type files Updated GetNestedType signatures to accept UTF-8
UnsafeIntrinsics.cs Added TODO comment about avoiding string allocations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants