Skip to content

Optimize packed fixed-size repeated I/O - #199

Merged
dameng324 merged 4 commits into
mainfrom
Optimize-packed-fixed-size-repeated
Jul 2, 2026
Merged

Optimize packed fixed-size repeated I/O#199
dameng324 merged 4 commits into
mainfrom
Optimize-packed-fixed-size-repeated

Conversation

@dameng324

Copy link
Copy Markdown
Owner

Add fast little-endian memcopy paths for packed fixed-size repeated fields. Introduces src/LightProto/Serializer.PackedRepeated.cs with TryWritePackedRepeatedFieldLittleEndian, ParseRepeatedFieldIntoSpan and TryReadPackedRepeatedFieldLittleEndian (with NET5/NET8 optimizations). Update generator (Helper.cs) and parser files (Array.cs, IEnumerableReader.cs, IEnumerableWriter.cs) to use the fast paths; add ParsingPrimitives.ReadPackedFieldLittleEndian and update PublicAPI.Unshipped. Add tests for packed fixed32 serialization and ReadOnlySequence splitting in FixedSizePackedArrayTests and FixedSizePackedListTests. Improves performance and correctness when reading/writing packed primitive arrays/lists.

Add fast little-endian memcopy paths for packed fixed-size repeated fields. Introduces src/LightProto/Serializer.PackedRepeated.cs with TryWritePackedRepeatedFieldLittleEndian, ParseRepeatedFieldIntoSpan and TryReadPackedRepeatedFieldLittleEndian (with NET5/NET8 optimizations). Update generator (Helper.cs) and parser files (Array.cs, IEnumerableReader.cs, IEnumerableWriter.cs) to use the fast paths; add ParsingPrimitives.ReadPackedFieldLittleEndian and update PublicAPI.Unshipped. Add tests for packed fixed32 serialization and ReadOnlySequence splitting in FixedSizePackedArrayTests and FixedSizePackedListTests. Improves performance and correctness when reading/writing packed primitive arrays/lists.
@codacy-production

codacy-production Bot commented Jul 2, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 41 complexity · 0 duplication

Metric Results
Complexity 41
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Move packed-repeated helper methods out of Serializer into a new PackedRepeatedOptimizer class (rename file and update type). Update generator and parser/writer call sites to use PackedRepeatedOptimizer. Add NETSTANDARD2_0-safe CreateSpan implementation and switch to itemReader.ParseMessageFrom calls. Update PublicAPI.Unshipped lists to reflect the new API surface. Refactor-only and adds span compatibility for netstandard2.0; behavior unchanged.
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.73394% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.19%. Comparing base (e8a22bb) to head (198147e).

Files with missing lines Patch % Lines
src/LightProto/PackedRepeatedOptimizer.cs 76.66% 14 Missing and 7 partials ⚠️

❌ Your patch check has failed because the patch coverage (80.73%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #199      +/-   ##
==========================================
- Coverage   95.67%   95.19%   -0.49%     
==========================================
  Files         124      125       +1     
  Lines        3287     3394     +107     
  Branches      441      464      +23     
==========================================
+ Hits         3145     3231      +86     
- Misses         76       90      +14     
- Partials       66       73       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

This comment has been minimized.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.301
  [Host]    : .NET 8.0.28 (8.0.28, 8.0.2826.26413), X64 RyuJIT x86-64-v3
  .NET 10.0 : .NET 10.0.9 (10.0.9, 10.0.926.27113), X64 RyuJIT x86-64-v3
  .NET 8.0  : .NET 8.0.28 (8.0.28, 8.0.2826.26413), X64 RyuJIT x86-64-v3
  .NET 9.0  : .NET 9.0.17 (9.0.17, 9.0.1726.26416), X64 RyuJIT x86-64-v3


Method Job Runtime Mean Error StdDev Ratio Allocated Alloc Ratio
Deserialize_ProtoBuf_net .NET 10.0 .NET 10.0 759.0 μs 3.14 μs 2.94 μs 1.31 562 KB 0.98
Deserialize_GoogleProtoBuf .NET 10.0 .NET 10.0 628.6 μs 3.14 μs 2.78 μs 1.08 648.7 KB 1.13
Deserialize_LightProto .NET 10.0 .NET 10.0 580.6 μs 2.40 μs 2.25 μs 1.00 574.8 KB 1.00
Deserialize_ProtoBuf_net .NET 8.0 .NET 8.0 886.7 μs 3.56 μs 2.97 μs 1.44 562 KB 0.98
Deserialize_GoogleProtoBuf .NET 8.0 .NET 8.0 805.7 μs 3.39 μs 3.01 μs 1.31 648.7 KB 1.13
Deserialize_LightProto .NET 8.0 .NET 8.0 617.2 μs 2.52 μs 2.23 μs 1.00 574.8 KB 1.00
Deserialize_ProtoBuf_net .NET 9.0 .NET 9.0 843.4 μs 2.57 μs 2.41 μs 1.35 562 KB 0.98
Deserialize_GoogleProtoBuf .NET 9.0 .NET 9.0 731.8 μs 3.47 μs 3.08 μs 1.17 648.7 KB 1.13
Deserialize_LightProto .NET 9.0 .NET 9.0 623.2 μs 2.54 μs 2.38 μs 1.00 574.8 KB 1.00

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.301
  [Host]    : .NET 8.0.28 (8.0.28, 8.0.2826.26413), X64 RyuJIT x86-64-v3
  .NET 10.0 : .NET 10.0.9 (10.0.9, 10.0.926.27113), X64 RyuJIT x86-64-v3
  .NET 8.0  : .NET 8.0.28 (8.0.28, 8.0.2826.26413), X64 RyuJIT x86-64-v3
  .NET 9.0  : .NET 9.0.17 (9.0.17, 9.0.1726.26416), X64 RyuJIT x86-64-v3


Method Job Runtime Mean Error StdDev Ratio Allocated Alloc Ratio
Serialize_ProtoBuf_net .NET 10.0 .NET 10.0 905.3 μs 2.11 μs 1.87 μs 1.30 526.41 KB 1.03
Serialize_GoogleProtoBuf .NET 10.0 .NET 10.0 785.6 μs 1.19 μs 1.05 μs 1.13 512.95 KB 1.00
Serialize_LightProto .NET 10.0 .NET 10.0 693.7 μs 1.87 μs 1.75 μs 1.00 512.92 KB 1.00
Serialize_ProtoBuf_net .NET 8.0 .NET 8.0 1,038.9 μs 2.89 μs 2.56 μs 1.35 526.4 KB 1.03
Serialize_GoogleProtoBuf .NET 8.0 .NET 8.0 813.1 μs 2.27 μs 1.90 μs 1.06 512.95 KB 1.00
Serialize_LightProto .NET 8.0 .NET 8.0 768.1 μs 1.34 μs 1.19 μs 1.00 512.92 KB 1.00
Serialize_ProtoBuf_net .NET 9.0 .NET 9.0 959.3 μs 3.25 μs 3.04 μs 1.27 526.41 KB 1.03
Serialize_GoogleProtoBuf .NET 9.0 .NET 9.0 791.4 μs 2.37 μs 2.10 μs 1.05 512.95 KB 1.00
Serialize_LightProto .NET 9.0 .NET 9.0 752.5 μs 2.75 μs 2.44 μs 1.00 512.92 KB 1.00

@dameng324
dameng324 merged commit 5b7b714 into main Jul 2, 2026
7 of 8 checks passed
@dameng324
dameng324 deleted the Optimize-packed-fixed-size-repeated branch July 2, 2026 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant