| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
@dotnet-policy-service agree |
Sorry, something went wrong.
Add TryReadFixIntArray to MessagePackReader that reads positive fixint (0x00-0x7f) encoded int arrays in a single pass instead of calling ReadInt32 per element. Falls back to element-by-element on non-fixint data with zero overhead. Profiled with metreja (5 runs, inlining enabled): - Deserialize inclusive: -15% - ReadInt32 calls: 3.49M → 1.00M (-71%) - Per-array: ~6,200ns → ~952ns (6.5x faster for 100-element fixint array) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Thanks for submitting. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Add a fast path to Int32ArrayFormatter.Deserialize that bulk-reads fixint-encoded int arrays in a single pass instead of calling ReadInt32() per element.
How it works
MessagePack encodes small integers (0–127) as a single byte called "positive fixint" — the byte value is the integer. The existing code deserializes int[] by calling ReadInt32() in a loop, which for each element: dispatches through format detection, decodes the value, and advances the reader.
The new TryReadFixIntArray method iterates the unread span once, validating each byte is ≤ 0x7f and copying it to the output array in the same loop. If any byte fails the check, it bails early and the caller falls back to the original element-by-element ReadInt32 loop — the fallback overwrites any partial data.
Fixint values (0–127) are common in int arrays: enum values, indices, counts, flags, IDs, and game state data.
Per-array cost (100-element fixint array)
Changes
Profiling
Profiled with metreja using a 1M serialize+deserialize harness, method_stats events, inlining enabled. 5 runs for statistical confidence.
metreja v1.0.20, macOS ARM64 (Apple M1 Pro), .NET 10.0.2
Test plan
🤖 Generated with Claude Code