Skip to content

Conversation

@alexggh
Copy link
Contributor

@alexggh alexggh commented Jan 22, 2026

By reserving the memory in advance we halve the encoding speed which ultimately speeds up the statement.hash() function which gets called in a lot of places.

More importantly, when we start being connected to more nodes the hash function gets called a lot for the same statement because we might receive the same statement from all peers we are connected to.

For example on versi on_statements ate a lot of time when running with 15 nodes, see #10814 (comment).

Modified the statement_network benchmark to also be parameterizable by the number of times we might receive a statement and if we receive it from 16 peers, we notice a speed up with this PR of ~16%, which I consider not negligible, so I consider this an worthy improvement.

on_statements/statements_2000/peers_16/threads_8/blocking
                        time:   [22.099 ms 22.641 ms 23.175 ms]
                        change: [-18.841% -16.637% -14.429%] (p = 0.00 < 0.05)

Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
Signed-off-by: Alexandru Gheorghe <alexandru.gheorghe@parity.io>
@alexggh alexggh added the T8-polkadot This PR/Issue is related to/affects the Polkadot network. label Jan 23, 2026
Copy link
Contributor

@AndreiEres AndreiEres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we reduce calls of hash() then and pass it into arguments where it's possible?

queue_sender,
metrics: None,
initial_sync_timeout: Box::pin(tokio::time::sleep(INITIAL_SYNC_BURST_INTERVAL).fuse()),
initial_sync_timeout: Box::pin(pending().fuse()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How it's related?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

benchmark was crashing because tokio time wants a tokio runtime.

self.num_topics as u32;

let mut output = Vec::new();
// Calculate capacity for preallocation using size_of for type sizes:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust size or SCALE-encoded size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the SCALE-encoded is what we want and this is a close approximation without actually scale encoding.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put it in a comment please?

Co-authored-by: Andrei Eres <eresav@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T8-polkadot This PR/Issue is related to/affects the Polkadot network.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants