improve the performance of trimming shape run cache#298
Open
dzhou121 wants to merge 7 commits intopop-os:mainfrom
Open
improve the performance of trimming shape run cache#298dzhou121 wants to merge 7 commits intopop-os:mainfrom
dzhou121 wants to merge 7 commits intopop-os:mainfrom
Conversation
jackpot51
reviewed
Sep 1, 2024
Member
|
Sorry for the delay in reviewing. I have one item I would like fixed. |
jackpot51
previously approved these changes
Sep 1, 2024
Member
|
Looks like Rust/build CI is failing |
UkoeHB
reviewed
Sep 3, 2024
Comment on lines
+75
to
+67
| // insert a new registry to the front of the Vec | ||
| // to keep keys for the current age | ||
| self.age_registries.insert(0, HashSet::default()); |
Contributor
There was a problem hiding this comment.
You can potentially reuse a hashset popped earlier.
Author
|
Can you please re-run the CI? |
jackpot51
reviewed
Sep 5, 2024
jackpot51
approved these changes
Sep 6, 2024
Member
|
This looks good to me. Given that @UkoeHB also provided feedback, I'd like a re-review from them as well. |
UkoeHB
suggested changes
Sep 6, 2024
Comment on lines
+43
to
+50
| self.age_registries[index].remove(key); | ||
|
|
||
| // update age | ||
| *age = self.age; | ||
| // register the key to the new age registry | ||
| if let Some(keys) = self.age_registries.first_mut() { | ||
| keys.insert(key.clone()); | ||
| } |
Contributor
There was a problem hiding this comment.
Suggested change
| self.age_registries[index].remove(key); | |
| // update age | |
| *age = self.age; | |
| // register the key to the new age registry | |
| if let Some(keys) = self.age_registries.first_mut() { | |
| keys.insert(key.clone()); | |
| } | |
| let prev_copy = self.age_registries[index].take(key); | |
| // update age | |
| *age = self.age; | |
| // register the key to the new age registry | |
| if let Some(keys) = self.age_registries.first_mut() { | |
| // Note: This is only valid so long as the PartialEq impl on ShapeRunKey checks value | |
| // equality. | |
| keys.insert(prev_copy.expect("age_registries should have entry if cache has entry")); | |
| } |
Comment on lines
+68
to
+75
| // and remove the keys from cache saved in the registries | ||
| while self.age_registries.len() as u64 > keep_ages { | ||
| if let Some(keys) = self.age_registries.pop() { | ||
| for key in keys { | ||
| self.cache.remove(&key); | ||
| } | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
Suggested change
| // and remove the keys from cache saved in the registries | |
| while self.age_registries.len() as u64 > keep_ages { | |
| if let Some(keys) = self.age_registries.pop() { | |
| for key in keys { | |
| self.cache.remove(&key); | |
| } | |
| } | |
| } | |
| // and remove the keys from cache saved in the registries | |
| let mut recovered_keys: Option<HashSet<ShapeRunKey>> = None; | |
| while self.age_registries.len() as u64 > keep_ages { | |
| if let Some(keys) = self.age_registries.pop() { | |
| for key in keys.drain() { | |
| self.cache.remove(&key); | |
| } | |
| if recovered_keys.is_none() { | |
| recovered_keys = Some(keys); | |
| } | |
| } | |
| } |
| self.age += 1; | ||
| // insert a new registry to the front of the Vec | ||
| // to keep keys for the current age | ||
| self.age_registries.insert(0, HashSet::default()); |
Contributor
There was a problem hiding this comment.
Suggested change
| self.age_registries.insert(0, HashSet::default()); | |
| self.age_registries.insert(0, recovered_keys.unwrap_or_default()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When shape run cache was trimmed with a large
keep_ages, it's expensive to scan the whole cache.This PR is trying to save the cache keys to a Vec of age registries, and when doing trim, pop the
Vecaccording tokeep_agesand those are the keys that needed to be removed from the cache.