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

deps: replace lru with schnellru #1217

Merged
merged 2 commits into from
Aug 28, 2023
Merged

Conversation

ordian
Copy link
Member

@ordian ordian commented Aug 28, 2023

Similar to substrate PR: paritytech/substrate#13802, this PR replaces usages of lru with schnellru in polkadot and cumulus.
Reasons:

  • Main: the name is obviously better
  • It's faster
  • Better tested (miri + fuzz tests)
  • Written by our own @koute

@ordian ordian added R0-silent Changes should not be mentioned in any release notes T0-node This PR/Issue is related to the topic “node”. labels Aug 28, 2023
@@ -112,118 +109,118 @@ impl RequestResultCache {
&mut self,
relay_parent: &Hash,
) -> Option<&Vec<AuthorityDiscoveryId>> {
self.authorities.get(relay_parent)
self.authorities.peek(relay_parent)
Copy link
Member Author

Choose a reason for hiding this comment

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

there's a small change in logic, as peek won't have an effect on order, but I think it's fine in our case

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 explain (for someone like me who isn't super familiar with this code and might not understand all of the consequences) why did you change this? Is it just unnecessary?

Maybe it could be interesting to empirically see whether this affects the cache hit rate in any measurable way? (The trie cache has some code which tracks the hit rate, so it could be transplanted/stolen as permanent debug logs here. I think it's always good to have some real data for stuff like this; if nothing else it can be used to pick an appropriate size for the caches. Although for 26 different LRU caches it might not really be practical, so maybe it'd be nice to add something like that to schnellru directly, hmm....)

Also, if you're doing this then you can also change &mut self to &self. (:

(Same for other places, as I can see you nuked every .get here.)

Copy link
Member Author

Choose a reason for hiding this comment

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

It was the easiest way to satisfy the compiler since the get method in schnellru returns Option<&mut V> instead of Option<&V> :)

But what I meant by "I think it's fine for our use-case" is that it shouldn't really affect the hit rate given that the insertion order should roughly match the read order.

I've now reverted this change to keep the previous behavior.

let val = self
.cache
.get_or_insert(*slot, || 0)
.expect("insertion with ByLength limiter always succeeds; qed");
Copy link
Contributor

Choose a reason for hiding this comment

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

This is correct, as long as the limit is not zero. (:

@@ -112,118 +109,118 @@ impl RequestResultCache {
&mut self,
relay_parent: &Hash,
) -> Option<&Vec<AuthorityDiscoveryId>> {
self.authorities.get(relay_parent)
self.authorities.peek(relay_parent)
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 explain (for someone like me who isn't super familiar with this code and might not understand all of the consequences) why did you change this? Is it just unnecessary?

Maybe it could be interesting to empirically see whether this affects the cache hit rate in any measurable way? (The trie cache has some code which tracks the hit rate, so it could be transplanted/stolen as permanent debug logs here. I think it's always good to have some real data for stuff like this; if nothing else it can be used to pick an appropriate size for the caches. Although for 26 different LRU caches it might not really be practical, so maybe it'd be nice to add something like that to schnellru directly, hmm....)

Also, if you're doing this then you can also change &mut self to &self. (:

(Same for other places, as I can see you nuked every .get here.)

@ordian ordian merged commit c168a77 into master Aug 28, 2023
79 of 100 checks passed
@ordian ordian deleted the ao-replace-lru-with-schnellru branch August 28, 2023 17:04
Daanvdplas pushed a commit that referenced this pull request Sep 11, 2023
* deps: replace lru with schnellru

* bring the peace to the galaxy
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 8, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 9, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 10, 2024
serban300 pushed a commit to serban300/polkadot-sdk that referenced this pull request Apr 10, 2024
bkchr pushed a commit that referenced this pull request Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R0-silent Changes should not be mentioned in any release notes T0-node This PR/Issue is related to the topic “node”.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants