Skip to content

Commit 6bbaeea

Browse files
perf(generator): add aggressive inlining to SerializeImpl/DeserializeImpl methods
Add MethodImpl(AggressiveInlining) attribute to generated Impl methods: **SerializeImpl:** - Mark SerializeImpl with AggressiveInlining attribute - Ensures JIT compiler inlines these methods at call sites - Critical for sealed type optimization to eliminate delegate overhead **DeserializeImpl/DeserializeImplRef:** - Mark both DeserializeImpl and DeserializeImplRef with AggressiveInlining - Enables direct inlining when called from generated code - Reduces call stack depth for sealed/struct deserialization These attributes work in conjunction with the sealed type inlining optimization to ensure the JIT can inline the complete serialization/deserialization logic, eliminating all delegate and method call overhead for maximum performance. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c6bc61f commit 6bbaeea

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

src/Nino.Generator/Common/DeserializerGenerator.Trivial.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ private void GenerateImpl(SourceProductionContext spc, StringBuilder sb, NinoTyp
8686
string suffix = byRef ? "Ref" : "";
8787

8888
sb.AppendLine($$"""
89+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8990
public static void DeserializeImpl{{suffix}}({{decl}} {{ninoType.TypeSymbol.GetTypeFullName()}} value, ref Reader reader)
9091
{
9192
#if {{NinoTypeHelper.WeakVersionToleranceSymbol}}

src/Nino.Generator/Common/SerializerGenerator.Trivial.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ private void GenerateTrivialCode(SourceProductionContext spc, HashSet<ITypeSymbo
3030
continue;
3131
sb.AppendLine();
3232
sb.AppendLine($$"""
33+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3334
public static void SerializeImpl({{ninoType.TypeSymbol.GetTypeFullName()}} value, ref Writer writer)
3435
{
3536
""");

0 commit comments

Comments
 (0)