Enable RuboCop Style/UnpackFirst - #3722
Merged
Merged
Conversation
Client: rb Co-Authored-By: OpenAI Codex (GPT-5.6) <codex@openai.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Enables RuboCop Style/UnpackFirst for the Ruby codebase and updates Ruby library + specs to use String#unpack1 in places that previously used unpack(...).first (or single-value parallel assignment), reducing intermediate array allocations in hot paths.
Changes:
- Enable
Style/UnpackFirstinlib/rb/.rubocop.yml. - Replace
unpack(...).first/ single-value unpacking withunpack1across Ruby library and specs. - Reduce allocations in protocol reads (notably binary i16/i32/double) and UUID hex decoding by avoiding intermediate arrays.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| lib/rb/.rubocop.yml | Enables Style/UnpackFirst to enforce unpack1 usage. |
| lib/rb/lib/thrift/protocol/binary_protocol.rb | Uses unpack1 for i16/i32/double reads to avoid intermediate arrays. |
| lib/rb/lib/thrift/protocol/compact_protocol.rb | Uses unpack1 for protocol id and double reads. |
| lib/rb/lib/thrift/server/nonblocking_server.rb | Uses unpack1 when decoding framed message sizes. |
| lib/rb/lib/thrift/struct_union.rb | Uses unpack1 for binary-to-hex inspection formatting. |
| lib/rb/lib/thrift/transport/framed_transport.rb | Uses unpack1 when reading frame size. |
| lib/rb/lib/thrift/transport/header_transport.rb | Uses unpack1 for frame size, magic, flags, and header parsing. |
| lib/rb/lib/thrift/uuid.rb | Uses unpack1 for UUID hex decoding from bytes. |
| lib/rb/spec/header_protocol_spec.rb | Updates spec assertions to use unpack1. |
| lib/rb/spec/header_transport_spec.rb | Updates spec assertions to use unpack1. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enable
Style/UnpackFirstand replace single-valueunpack(...).firstand parallel-assignment unpacking withunpack1throughout the Ruby library and tests. Binary protocol i16 and i32 reads now avoid an intermediate array alongside double reads and UUID byte decoding.Benchmarks
The repository protocol benchmark compared
upstream/masterwith this branch using Ruby 4.0.6 on aarch64 Linux. Each result is the median of seven isolated invocations; every invocation includes the harness warm-up pass.upstream/masterA separate stdlib-only primitive benchmark measured 500,000 operations in isolated processes with GC disabled. Each replacement removed one allocation per operation and reduced retained memory:
G)H*)n)N)The protocol benchmark measures only the selected pure-Ruby read scenarios, while the primitive benchmark isolates unpacking allocation cost; neither predicts complete application throughput.
[skip ci]anywhere in the commit message to free up build resources.