a33dbecb
wire: encode_varint 1-byte fast path (up to 3.8× encode throughput)
For non-negative Lua numbers under 0x80, return string.char(n) directly — no `to_uint64` cdata allocation, no `out` table, no table.concat. Covers the dominant case for typical payloads: length prefixes for strings <128 bytes, small int field values, enum ordinals, and most tag bytes when codegen-precomputation isn't available. Symmetric to the decode_varint 1-byte fast path in 9f3bfb8 but the payoff is much bigger because the encode path was paying for both a cdata allocation and a list-builder per call, not just a varint loop. Effect (bench/bench.lua, hello.Person): full/10B encode: 13 → 30 MB/s (2.3×) full/100B encode: 125 → 278 MB/s (2.2×) full/1KB encode: 69 → 210 MB/s (3.0×) full/10KB encode: 98 → 352 MB/s (3.6×) full/100KB encode: 108 → 398 MB/s (3.7×) runtime/10B encode: 9 → 16 MB/s (1.8×) runtime/100B encode: 78 → 151 MB/s (1.9×) runtime/1KB encode: 68 → 183 MB/s (2.7×) runtime/10KB encode: 99 → 352 MB/s (3.5×) runtime/100KB encode: 109 → 411 MB/s (3.8×) decode: unchanged alloc/op: unchanged (bench-compare clean)
Eugene Blikh <bigbes@gmail.com> — 2026-05-15 11:10:03 UTC
Commit a33dbecb99a102622400c46b461f679c9ad30662 —
view raw patch
Parent(s):
46045da1
| File | Status | + | − |
|---|---|---|---|
runtime/pb/wire.lua
|
M | +8 |