~bigbes/tarantool

tarantool-protobuf

ref: dbbfaf3555b5cd0fbc76ec1c9e69c5c87072dc97 tarantool-protobuf/bench/map_bench.lua -rw-r--r-- 1.9 KiB
0b6e1bc5 — Eugene Blikh 2 months ago
bench: add map_bench.lua, close ch2 (intervention regresses)

ch2 hypothesized that replacing `for k, v in pairs(map_value) do` in
the codegen-emitted map encoder with a key-collect + ipairs pattern
would let the inner emit loop stay on a JIT trace. Hand-implemented in
both codegen (inline.go:emitInlineEncodeMap) and runtime
(codec.lua kind=='map' branch); 752/752 tests passed.

Bench (work.lab.local, median of 3, Person.ages_by_nickname encode):

  map size | BEFORE      | AFTER       |  Δ
       1   |  1,282,180  |  1,128,545  | -12%
       3   |    634,880  |    549,761  | -13%
      10   |    215,745  |    196,800  |  -9%
      50   |     48,162  |     45,614  |  -5%
     200   |     11,613  |     11,282  |  -3%

Regression across all sizes. LuaJIT's side-trace machinery was already
JIT-ing the inner body via a side trace from the pairs() ISNEXT abort
point — the body was already on-trace before. The change just adds
wrapper overhead (scratch table alloc, O(N) key-collection, extra hash
lookup per entry).

Reverted the codegen + runtime edits. Keeping bench/map_bench.lua —
useful harness for any future map-encoder work (e.g. x9f deterministic
ordering may revisit this).

See ch2 bd notes for full diagnosis.