kpumuk opened a new pull request, #3703:
URL: https://github.com/apache/thrift/pull/3703
<!-- Explain the changes in the pull request below: -->
Ruby's CompactProtocol writers accept integers outside the widths declared
by the Thrift type system. An out-of-range value can therefore be serialized
without an error, change when decoded, and behave differently depending on
whether the native extension is loaded.
This change validates fixed-width integers, field identifiers, message
sequence identifiers, and collection or binary sizes before writing bytes or
changing protocol state. Native and pure-Ruby implementations now follow the
same bounds, while protocol-owned header bytes continue to use their unsigned
wire representation.
The pure-Ruby varint writers also collect multi-byte values into a single
transport write. This avoids a performance penalty from the added validation
and reduces temporary allocations without changing valid wire encodings.
## Benchmarks
The protocol benchmark was run in seven fresh processes for both
`upstream/master` and this change. Pure-Ruby runs additionally set
`THRIFT_BENCHMARK_SKIP_NATIVE=1`.
```sh
ruby ../../test/rb/benchmarks/protocol_benchmark.rb \
--small-runs 30000 \
--large-runs 2 \
--scenarios rb-cmp-write-small,rb-cmp-write-large,hdr-cmp-write-small \
--json
```
| Mode and scenario | Master median | Proposed median | Change |
|---|---:|---:|---:|
| Native Compact, small structures | 0.155830s | 0.154606s | -0.79% |
| Native Compact, large structure | 0.209833s | 0.209450s | -0.18% |
| Native Header/Compact, small structures | 0.377205s | 0.372075s | -1.36% |
| Pure-Ruby Compact, small structures | 0.467134s | 0.450486s | -3.56% |
| Pure-Ruby Compact, large structure | 0.643928s | 0.631595s | -1.92% |
| Pure-Ruby Header/Compact, small structures | 0.621219s | 0.607185s |
-2.26% |
A targeted allocation benchmark encoding 500,000 representative varints
reduced temporary allocations from 4,500,009 to 1,400,004.
These measurements used Ruby 4.0.6 on aarch64 Linux; they do not represent a
cross-version or cross-platform benchmark matrix.
<!-- We recommend you review the checklist/tips before submitting a pull
request. -->
- [x] Did you create an [Apache
Jira](https://issues.apache.org/jira/projects/THRIFT/issues/) ticket?
[THRIFT-6139](https://issues.apache.org/jira/browse/THRIFT-6139)
- [x] If a ticket exists: Does your pull request title follow the pattern
"THRIFT-NNNN: describe my issue"?
- [x] Did you squash your changes to a single commit? (not required, but
preferred)
- [x] 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.
<!--
The Contributing Guide at:
https://github.com/apache/thrift/blob/master/CONTRIBUTING.md
has more details and tips for committing properly.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]