-
Notifications
You must be signed in to change notification settings - Fork 97
rust: Use minimum internal buffer size of 128b #1080
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
a76fe1e to
dc9e0d8
Compare
|
|
||
| fn parse_unchecked<B: Buf>(buf: &mut B) -> Self { | ||
| let mut v = Vec::new(); | ||
| let mut v = Vec::with_capacity(BUFLEN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would something like this work?
let mut v = Vec::with_capacity(BUFLEN / mem::size_of::<T>());it should over-allocate less often. but I think the buffer sizes would vary more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this which didn't seem to have any impact:
diff --git a/rust/sbp/src/wire_format.rs b/rust/sbp/src/wire_format.rs
index afdd09fd..3d3639d3 100644
--- a/rust/sbp/src/wire_format.rs
+++ b/rust/sbp/src/wire_format.rs
@@ -53,7 +53,7 @@ where
}
fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
- let mut v = Vec::with_capacity(BUFLEN);
+ let mut v = Vec::with_capacity(64*(1+(mem::size_of::<T>() / 64)));
while buf.remaining() >= T::MIN_LEN {
v.push(T::parse_unchecked(buf));
}
Benchmark:
Benchmark #1: sbp2json <test_data/benchmark.sbp | json2sbp >/dev/null
Time (mean ± σ): 610.7 ms ± 18.9 ms [User: 936.4 ms, System: 161.0 ms]
Range (min … max): 561.0 ms … 684.1 ms 50 runs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smaller internal buffer size of 64 bytes was a bit slower:
Benchmark #1: sbp2json <test_data/benchmark.sbp | json2sbp >/dev/null
Time (mean ± σ): 629.7 ms ± 18.2 ms [User: 979.7 ms, System: 151.9 ms]
Range (min … max): 584.6 ms … 678.3 ms 50 runs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buffer size of 256:
Benchmark #1: sbp2json <test_data/benchmark.sbp | json2sbp >/dev/null
Time (mean ± σ): 624.5 ms ± 18.7 ms [User: 962.8 ms, System: 159.4 ms]
Range (min … max): 587.7 ms … 698.3 ms 50 runs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm interesting, I guess T is typically small anyway
rust/sbp2json/Cargo.toml
Outdated
| env_logger = "0.8" | ||
| serde_json = "1.0" | ||
| structopt = "0.3" | ||
| mimalloc = { version = "*", default-features = false } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to not have a version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No version is what the docs for the package recommended but they didn't give a rational, I can pin it
94a3832 to
5f86c8a
Compare
|
|
improves speed and also works on non-Linux platforms
improves perf by allow the allocator to do less work when reclaiming memory
5f86c8a to
566faaa
Compare
no worries, I figured it out |
Benchmarks, jemalloc without 128b minimum buffer size:
Using jemalloc with 128b minimum internal buffer size:
Using mimalloc with 128b minimum internal buffer size:
MiMalloc also has the benefit that it works for more than just Linux.