Skip to content
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

Add two caches to the peers state machine #2898

Merged
merged 6 commits into from
Oct 19, 2022
Merged

Conversation

tomaka
Copy link
Contributor

@tomaka tomaka commented Oct 19, 2022

The Peers state machine has two functions: unfulfilled_desired_outbound_substreams and fulfilled_undesired_outbound_substreams. They return a list of peer-substreams tuples.

These two functions are called very frequently (every time something happens on the networking), they are O(n) (they iterate over every single substream of every single peer), and most of the time they return nothing.

This PR adds two new fields to the peers state machine with the same names as these functions.
The functions now simply return the content of the field, and the field is updated pro-actively whenever something else changes.

Copy link
Contributor

@mergify mergify bot left a comment

Choose a reason for hiding this comment

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

Automatically approving tomaka's pull requests. This auto-approval will be removed once more maintainers are active.

@tomaka
Copy link
Contributor Author

tomaka commented Oct 19, 2022

Thanks to the debug_asserts!, I'm quite confident that the logic is correct. Every single time we make sure that the value is in there if it should be in there, or not in there if it shouldn't be in there. All the debug_asserts are run pretty frequently.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 19, 2022

twiggy diff report

Difference in .wasm size before and after this pull request.


 Delta Bytes │ Item
─────────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────
       +5146 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::next_event::h980ff9df389960cc
       -4192 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::next_event::h2c2d02ee4e653fb3
       +1140 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::set_peer_notifications_out_desired::hab52a248e2bbb5a5
       +1007 ┊ hashbrown::raw::RawTable<T,A>::reserve_rehash::h658b7f14370a3b29
       +1007 ┊ hashbrown::raw::RawTable<T,A>::reserve_rehash::hbeebf15ee4222fae
        -704 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::set_peer_notifications_out_desired::he5f941a9ffa40cd8
        +646 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::new::hf06eaab3702f6e13
        -606 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::new::h85fd8ef6ea9d3abc
        +557 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::close_out_notification::h74a44eb6af6bdfd3
        -495 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::try_clean_up_peer::h18aedf208639263d
        +495 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::try_clean_up_peer::hc88e6d9d994a4b15
        +347 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::open_out_notification::h12a81db841987995
        -341 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::close_out_notification::hbe99fc51ea335164
        -315 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::open_out_notification::h043a4466a921454d
        -309 ┊ core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut::hafc10ee55589d1f7
        -294 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::broadcast_notification::h5f1e15478bd0008a
        +294 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::broadcast_notification::he22b11517363a9af
        +287 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::connection_id_for_peer::hce194e99c000138e
        -287 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::connection_id_for_peer::hdedb363bcc7251af
        -265 ┊ smoldot::libp2p::peers::Peers<TConn,TNow>::add_multi_stream_outgoing_connection::h27635b17c9f943eb
       +3259 ┊ ... and 154 more.
      +10607 ┊ Σ [174 Total Rows]

Copy link
Contributor

@melekes melekes left a comment

Choose a reason for hiding this comment

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

👍

@tomaka tomaka added the automerge Automatically merge pull request as soon as possible label Oct 19, 2022
@mergify mergify bot merged commit c6fa161 into paritytech:main Oct 19, 2022
@tomaka tomaka deleted the peers-cache branch October 19, 2022 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge pull request as soon as possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants