Unverified Commit f6a4514a authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Preallocate correct-sized buffer for event stream (#4212)

## Motivation and Context

Currently when serializing event streams, an empty buffer is used. This
results in repeated reallocations as the buffer grows. However, we can
actually precalculate the exact size that is required.


<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here -->

## Description
<!--- Describe your changes in detail -->

This PR does two things:
1. Add a MessageSizeHint that aws-smithy-http can use to determine the
in-memory serialized size of the message
2. Add a benchmark of write_message. The benchmark includes an prototype
optimized implementation that we can switch to at a later date.

## Testing
- Benchmark
- Test of correctness for size calculation

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] For changes to the smithy-rs codegen or runtime crates, I have
created a changelog entry Markdown file in the `.changelog` directory,
specifying "client," "server," or both in the `applies_to` key.
- [x] For changes to the AWS SDK, generated SDK code, or SDK runtime
crates, I have created a changelog entry Markdown file in the
`.changelog` directory, specifying "aws-sdk-rust" in the `applies_to`
key.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent 685c31c7
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
---
applies_to:
- server
- client
- aws-sdk-rust
authors:
- rcoh
references: ["smithy-rs#4212"]
breaking: false
new_feature: false
bug_fix: false
---
Event streams now allocate a right-sized buffer avoiding repeated reallocations during serialization
+479 −39

File changed.

Preview size limit exceeded, changes collapsed.

+13 −1
Original line number Diff line number Diff line
[package]
name = "aws-smithy-eventstream"
# <IMPORTANT> Only patch releases can be made to this runtime crate until https://github.com/smithy-lang/smithy-rs/issues/3370 is resolved
version = "0.60.9"
version = "0.60.10"
# </IMPORTANT>
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>", "John DiSanti <jdisanti@amazon.com>"]
description = "Event stream logic for smithy-rs."
@@ -12,6 +12,8 @@ repository = "https://github.com/smithy-lang/smithy-rs"
[features]
derive-arbitrary = ["arbitrary", "derive_arbitrary"]
test-util = []
__bench-jemalloc = []
__bench-mimalloc = []

[dependencies]
arbitrary = { version = "1.3", optional = true }
@@ -22,6 +24,16 @@ derive_arbitrary = { version = "1.3", optional = true }

[dev-dependencies]
bytes-utils = "0.1"
criterion = { version = "0.5", features = ["html_reports"] }
mimalloc = { version = "0.1.43" }

# jemalloc doesn't work on windows, this breaks windows CI
[target.'cfg(not(target_os = "windows"))'.dev-dependencies]
jemallocator = { version = "0.5" }

[[bench]]
name = "write_message_performance"
harness = false

[package.metadata.docs.rs]
all-features = true
+484 −0

File added.

Preview size limit exceeded, changes collapsed.

+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ pub mod arbitrary;
mod buf;
pub mod error;
pub mod frame;
pub mod message_size_hint;
pub mod smithy;
#[cfg(feature = "test-util")]
pub mod test_util;
Loading