~bigbes/tarantool-protobuf: 117c6ef9

codegen: type-elision for sint64/fixed64/sfixed64 encode (a7l)

For mode=full the field type is statically known, so the codegen can
skip wire.to_int64 / wire.to_uint64's runtime type dispatch by pre-
casting at the call site:

  -- before
  out[n] = wire.encode_sint64(v)        -- calls to_int64(v) inside
  out[n] = wire.encode_fixed64(v)       -- calls to_uint64(v) inside

  -- after
  out[n] = wire.encode_sint64_i(INT64(v))   -- direct cdata path
  out[n] = wire.encode_fixed64_u(UINT64(v))
  out[n] = wire.encode_sfixed64_u(UINT64(v))

Wire-level: added encode_sint64_i / encode_fixed64_u / encode_sfixed64_u
alongside the existing encoders; encode_fixed64 is now a thin wrapper
that calls to_uint64 + encode_fixed64_u so the generic API surface stays
intact. INT64/UINT64 added as file-header upvalues in generated modules.

int32/int64/uint32/uint64 unchanged: those alias to encode_varint, which
only dispatches through to_uint64 on the slow-slow cdata path (large
negatives) — not worth the codegen surface.

Applied at every encode emit site that took a scalar: singular,
required, repeated non-packed, extension singular, extension repeated,
packed slow path, proto2 extension repeated. Map-value path also picks
it up via the shared helper.

c_int64.Wide encode (full mode, 4-run median):
  lua-num inputs   2769 -> 2520 ns/op   (+9.9% throughput)
  cdata inputs    12993 -> 12935 ns/op  (unchanged; to_uint64 already
                                         takes the cdata fast path)

Just below the issue's optimistic 10-15% but exactly the case that
matters — Lua-number inputs are the common case for user code on
sint64/fixed64 fields. Suites: test 766/766, test-c 1057/1057.

Eugene Blikh <bigbes@gmail.com> — 2026-05-24 21:02:51 UTC

Commit 117c6ef9c9919d3c49dc1712df9f3b604fdb607bview raw patch

Parent(s): 7b3d6901

22 changed file(s)

FileStatus+
.beads/issues.jsonl M +1 -1
cmd/protoc-gen-tarantool/internal/gen/gen.go M +6
cmd/protoc-gen-tarantool/internal/gen/inline.go M +33 -13
examples/expected/full/c_int64/c_int64_pb.lua M +6 -3
examples/expected/full/c_nested/c_nested_pb.lua M +3
examples/expected/full/c_repeated/c_repeated_pb.lua M +6 -3
examples/expected/full/conformance/conformance_pb.lua M +3
examples/expected/full/hello/hello_pb.lua M +4 -1
examples/expected/full/proto2_basic/proto2_basic_pb.lua M +3
examples/expected/full/protobuf_test_messages/proto2/test_messages_proto2_pb.lua M +36 -33
examples/expected/full/protobuf_test_messages/proto3/test_messages_proto3_pb.lua M +24 -21
examples/expected/full/quickstart/quickstart_pb.lua M +3
examples/expected/runtime/c_int64/c_int64_pb.lua M +3
examples/expected/runtime/c_nested/c_nested_pb.lua M +3
examples/expected/runtime/c_repeated/c_repeated_pb.lua M +3
examples/expected/runtime/conformance/conformance_pb.lua M +3
examples/expected/runtime/hello/hello_pb.lua M +3
examples/expected/runtime/proto2_basic/proto2_basic_pb.lua M +3
examples/expected/runtime/protobuf_test_messages/proto2/test_messages_proto2_pb.lua M +3
examples/expected/runtime/protobuf_test_messages/proto3/test_messages_proto3_pb.lua M +3
examples/expected/runtime/quickstart/quickstart_pb.lua M +3
runtime/pb/wire.lua M +30 -5