-
Notifications
You must be signed in to change notification settings - Fork 962
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
make noise transport perform less reallocations #4221
Comments
Sounds good to me! Ideally, we could accompany this with a (micro)-benchmark. Are you happy to prepare a PR? |
It would be even better if we could measure this improvement using the new performance benchmark suite: https://github.com/libp2p/test-plans/tree/master/perf |
Sure. I'd like to first test this in a polkadot test network, to see if it indeed is a noticeable improvement, because the flamegraph was gathered on a local machine. I'm having a bit of trouble updating the libp2p version in substrate, I get some unexpected compilation errors. I'll see if I can sort them out |
Check the release blog-post for a summary of all updates in the latest release: https://github.com/libp2p/rust-libp2p/releases/tag/libp2p-v0.52.0 |
paritytech/substrate#14429 should be merged sometime this week |
I finally managed to cherry-pick my changes onto the old version of libp2p that substrate uses and integrate that into polkadot. Still, I think it's a useful optimisation to make, even if it's just a micro-optimisation. I tried creating a micro-benchmark, using criterion and a scenario similar to the quickcheck smoke test present in the I'll open a small PR with my changes if you think they're valuable. |
If we can't prove that they are an improvement, it is difficult to argue for merging them :) Is there any other advantage, like an easier to reason about implementation? |
conceptually, it's quite obvious that it's an improvement. we just don't have the right benchmarking setup to prove it and building it is not trivial. I mimicked in a benchmark the logic of
The
|
Mind posting a PR with this? I'd like to see it with the context around it :) Judging just from this, it looks simple enough to merge it. |
here it is: #4230 |
Turns out this is not a visible problem when running a polkadot validator node. The initial diagnostic was performed on a full polkadot node that was not a validator (performing less work, so the resizes had a higher percentage). When profiling a validator under load-testing, this overhead becomes negligible in comparison. Therefore, I'll close this issue. While I think that #4230 is a useful addition for lighter clients, you may close it if you disagree, since we're not impacted by this (we have much higher network CPU conspumtion coming from other places) |
Thank you for the detailed report! |
Currently, the noise protocol implementation spends a lot of time performing vec resizes and truncations, which are costly on a vector that hasn't got a preallocated capacity:
rust-libp2p/transports/noise/src/io.rs
Line 122 in a49ad77
rust-libp2p/transports/noise/src/io/framed.rs
Line 336 in a49ad77
rust-libp2p/transports/noise/src/io/framed.rs
Line 343 in a49ad77
This is noticeable in a flamegraph gathered while running a polkadot node. About 15% of the overall sampled period is spent in vec resizes.
I suggest we modify the preallocated vector capacity to be of the maximum noise frame len 65535, which should be a pretty non-intrusive change.
The text was updated successfully, but these errors were encountered: