unbuffered: eliminate allocation in unbuffered bulk encrypt path#2698
unbuffered: eliminate allocation in unbuffered bulk encrypt path#2698hyrumcoop wants to merge 9 commits intorustls:mainfrom
Conversation
…ider to implement zero-allocation and zero-copy encryption
da9ba29 to
c831ad4
Compare
|
Looks very interesting! The |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2698 +/- ##
==========================================
- Coverage 94.87% 94.52% -0.35%
==========================================
Files 95 95
Lines 21794 22033 +239
Branches 614 616 +2
==========================================
+ Hits 20676 20826 +150
- Misses 992 1081 +89
Partials 126 126 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks for the feedback! That makes perfect sense. I’ve been exploring a few ways to adjust the Once I’ve worked through the details, I’ll open a separate design discussion issue for the MessageEncrypter trait so we can agree on the right direction before committing to any specific changes. |
|
Sounds great! FWIW, we already greatly appreciate the clear PR description and clean commit history. |
|
Hi @djc, thanks again for the feedback! I wanted to clarify a couple of things before continuing further:
|
No -- the
I mainly meant the latter, though in general I think we'd prefer to avoid duplication where that semantically makes sense. |
Summary
This PR eliminates allocations in the unbuffered API bulk encrypt path without modifying the public API. This is achieved by adding an
encrypt_intomethod on theMessageEncryptertrait that writes the encrypted record directly into a caller-provided buffer.To be less intrusive, I introduced the structs
PrefixedPayloadBorrowedandOutboundOpaqueMessageBorrowedalongside their owned counterparts. This temporarily duplicates some logic but leaves the original encrypt path untouched.Benchmarks
Hardware: AMD Ryzen 7 5800XT
Command:
BENCH_MULTIPLIER=32 taskset -c 4 ./target/release/rustls-bench --api=unbuffered bulk TLS13_AES_128_GCM_SHA256Across both allocators, throughput improved by ~4-5%.
Motivation
Beyond the modest throughput increase, removing allocations in this path:
Follow-up