瀏覽代碼

Speed up writing of messages with many fields

Jan Tattermusch 5 年之前
父節點
當前提交
468c3ba8c6
共有 1 個文件被更改,包括 5 次插入1 次删除
  1. 5 1
      csharp/src/Google.Protobuf/WritingPrimitives.cs

+ 5 - 1
csharp/src/Google.Protobuf/WritingPrimitives.cs

@@ -399,7 +399,11 @@ namespace Google.Protobuf
             }
             }
         }
         }
 
 
-        [MethodImpl(MethodImplOptions.AggressiveInlining)]
+        // This method is intentionally not marked as "AggressiveInlining", because it slows down
+        // serialization of messages with lots of empty fields. Likely explanation is that
+        // thw WriteRawTag invocations in InternalWriteTo method get inlined too deep and that makes
+        // skipping fields which are not present more expensive (which is especially constly for
+        // messages with lots of fields of which only a few are present).
         public static void WriteRawByte(ref Span<byte> buffer, ref WriterInternalState state, byte value)
         public static void WriteRawByte(ref Span<byte> buffer, ref WriterInternalState state, byte value)
         {
         {
             if (state.position == state.limit)
             if (state.position == state.limit)