Skip to content

THRIFT-6147: Finalize buffered Ruby serializer transports - #3711

Merged
kpumuk merged 1 commit into
apache:masterfrom
kpumuk:rb-header-serializer-flush
Aug 13, 2026
Merged

THRIFT-6147: Finalize buffered Ruby serializer transports#3711
kpumuk merged 1 commit into
apache:masterfrom
kpumuk:rb-header-serializer-flush

Conversation

@kpumuk

@kpumuk kpumuk commented Aug 12, 2026

Copy link
Copy Markdown
Member

Ruby Serializer reads its backing memory buffer immediately after writing a value through the selected protocol. That produces the expected bytes for protocols writing directly to MemoryBufferTransport, but transports such as Header and Framed retain their output until they are flushed. In those configurations, serialization succeeds while returning an empty string.

This change finalizes the transport exposed by the selected protocol before reading the serializer buffer. It relies on the existing transport contract: flushing a memory buffer remains a no-op, while buffering and framing transports complete their wire representation. The behavior therefore remains generic instead of coupling Serializer to specific protocol or transport classes.

Benchmarks

A targeted benchmark ran 50,000 ordinary serializer calls per protocol for five trials with:

bundle exec ruby -Ilib /tmp/serializer_benchmark.rb

The benchmark compared current master with this change under the same Ruby container and workload. Medians in seconds were:

Mode Protocol Master Proposed Delta
Native Binary 0.095683 0.095480 -0.2%
Native Compact 0.068843 0.067851 -1.4%
Native JSON 0.393388 0.392847 -0.1%
Pure Ruby Binary 0.130590 0.130288 -0.2%
Pure Ruby Compact 0.127151 0.128482 +1.0%
Pure Ruby JSON 0.470556 0.472781 +0.5%

The small differences are within run-to-run noise. This benchmark targets the existing direct-memory paths, where the new call resolves to a no-op flush. It does not compare Header or Framed throughput because master returns no serialized bytes for those configurations.

  • Did you create an Apache Jira ticket? THRIFT-6147
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources.

Client: rb

Co-Authored-By: OpenAI Codex (GPT-5.6) <codex@openai.com>
Copilot AI lite review requested due to automatic review settings August 12, 2026 19:23
@mergeable mergeable Bot added the ruby Pull requests that update Ruby code label Aug 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes Ruby Thrift::Serializer returning empty strings when the selected protocol uses buffered/framed transports (e.g., Header, Framed) by ensuring the protocol’s exposed transport is finalized before reading from the backing MemoryBufferTransport.

Changes:

  • Flush the protocol’s transport after writing (@protocol.trans.flush) so buffered transports emit their wire representation before the serializer reads the buffer.
  • Expand serializer specs to cover framed and Header protocol round-trips, and assert byte-for-byte stability for common protocol outputs.
  • Update existing protocol-factory-based serialization spec to expect a flush on the protocol transport.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
lib/rb/lib/thrift/serializer/serializer.rb Flushes the protocol transport before reading the memory buffer to finalize buffered/framed outputs.
lib/rb/spec/serializer_spec.rb Adds regression tests for framed and Header transports and checks output stability across standard protocols.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@kpumuk
kpumuk merged commit c621dc6 into apache:master Aug 13, 2026
94 of 95 checks passed
@kpumuk
kpumuk deleted the rb-header-serializer-flush branch August 13, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ruby Pull requests that update Ruby code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants