leitzler opened a new pull request, #3057:
URL: https://github.com/apache/thrift/pull/3057
Due to a subtle caveat in buffer.Bytes the Go binary protocol method
ReadBinary() always over-allocated.
We now allocate the asked size directly up to 10 MiB, and then maintain the
malformed message protection by using a 10 MiB buffer for larger asks.
The existing benchmarks show that we reduce allocations for small payloads,
and keep the edge case on a reasonable level at about 10MiB.
Ran the existing benchmarks in lib/go/thrift with and without this change:
% go test -run X -bench . -benchmem > <file>
% benchcmp -changed old.txt new.txt
[...]
benchmark old allocs new allocs
delta
BenchmarkSafeReadBytes/normal-20 5 2
-60.00%
BenchmarkSafeReadBytes/max-askedSize-20 8 3
-62.50%
BenchmarkBinaryBinary_0-20 4 1
-75.00%
BenchmarkBinaryBinary_1-20 4 1
-75.00%
BenchmarkBinaryBinary_2-20 5 2
-60.00%
BenchmarkCompactBinary0-20 4 1
-75.00%
BenchmarkCompactBinary1-20 4 1
-75.00%
BenchmarkCompactBinary2-20 5 2
-60.00%
BenchmarkSerializer/baseline-20 8 5
-37.50%
BenchmarkSerializer/plain-20 20 17
-15.00%
BenchmarkSerializer/pool-20 8 5
-37.50%
benchmark old bytes new bytes delta
BenchmarkSafeReadBytes/normal-20 1656 160
-90.34%
BenchmarkSafeReadBytes/max-askedSize-20 15992 10489910
+65494.73%
BenchmarkBinaryBinary_0-20 1608 160
-90.05%
BenchmarkBinaryBinary_1-20 1608 160
-90.05%
BenchmarkBinaryBinary_2-20 1634 184
-88.74%
BenchmarkCompactBinary0-20 1608 160
-90.05%
BenchmarkCompactBinary1-20 1608 160
-90.05%
BenchmarkCompactBinary2-20 1634 184
-88.74%
BenchmarkSerializer/baseline-20 1000 416
-58.40%
BenchmarkSerializer/plain-20 3640 3056
-16.04%
BenchmarkSerializer/pool-20 1002 417
-58.38%
<!-- Explain the changes in the pull request below: -->
<!-- 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?
([Request account here](https://selfserve.apache.org/jira-account.html), not
required for trivial changes)
- [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]