Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

perf(YouTube): Reduce memory requirement for prefix tree searching #501

Conversation

LisoUseInAIKyrios
Copy link
Contributor

@LisoUseInAIKyrios LisoUseInAIKyrios commented Oct 16, 2023

Modified the prefix search to use a variable sized array which reduces memory usage.

Before this PR:
LithoFilterPatch: Using: 8 identifier filters (1 KB), 71 path filters (47 KB)
This PR:
LithoFilterPatch: Using: 8 identifier filters (1 KB), 71 path filters (5 KB)

Overall memory was already low. But the main benefit is less cpu cache churn, since it no longer loads cache lines that are mostly null.

On first startup it does require rehashing the node array as the filter patterns are added, but that takes 2 milliseconds total on a modern device (and that 2ms is only required once)

For reference, here is the rehashing the default litho filters go thru on app startup:

LithoFilterPatch: Starting prefix search initialization
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 2 times from size: 3 to size: 7
TrieSearch: Resized child array 5 times from size: 7 to size: 17
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 2 times from size: 3 to size: 7
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 2 times from size: 3 to size: 7
TrieSearch: Resized child array 1 times from size: 3 to size: 5
TrieSearch: Resized child array 1 times from size: 5 to size: 7
TrieSearch: Resized child array 2 times from size: 3 to size: 7
TrieSearch: Resized child array 6 times from size: 7 to size: 19
TrieSearch: Resized child array 2 times from size: 19 to size: 23
TrieSearch: Resized child array 1 times from size: 23 to size: 25
TrieSearch: Resized child array 4 times from size: 25 to size: 33   // Comment: this is the root node (first character of all patterns), which is why it's the largest
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 2 times from size: 1 to size: 5
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 2 times from size: 1 to size: 5
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 2 times from size: 3 to size: 7
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 3 times from size: 3 to size: 9
TrieSearch: Resized child array 2 times from size: 1 to size: 5
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 2 times from size: 1 to size: 5
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 3 to size: 5
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 2 times from size: 5 to size: 9
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 2 times from size: 3 to size: 7
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 2 times from size: 1 to size: 5
TrieSearch: Resized child array 1 times from size: 1 to size: 3
TrieSearch: Resized child array 1 times from size: 3 to size: 5
TrieSearch: Resized child array 3 times from size: 1 to size: 7
LithoFilterPatch: Prefix search initialization took: 2ms

@LisoUseInAIKyrios LisoUseInAIKyrios merged commit f5add51 into ReVanced:dev Oct 17, 2023
1 check passed
@LisoUseInAIKyrios LisoUseInAIKyrios deleted the prefix_search_optimize_hashtable_size branch October 17, 2023 10:08
revanced-bot pushed a commit that referenced this pull request Oct 17, 2023
# [0.120.0-dev.4](v0.120.0-dev.3...v0.120.0-dev.4) (2023-10-17)

### Performance Improvements

* **YouTube:** Reduce memory requirement for prefix tree searching ([#501](#501)) ([f5add51](f5add51))
revanced-bot pushed a commit that referenced this pull request Oct 20, 2023
# [0.120.0](v0.119.2...v0.120.0) (2023-10-20)

### Bug Fixes

* **YouTube - Hide Layout components:** Exempt expandable chips from exceptions ([#498](#498)) ([6f79746](6f79746))
* **YouTube - Hide layout components:** Hide new channel watermark component ([9670bd3](9670bd3))
* **YouTube - Minimized playback:** Fix pip incorrectly showing if app is minimized immediately after opening a Short ([7d02774](7d02774))
* **YouTube - Old video quality menu:** Fix toast error on tablet devices ([#500](#500)) ([d3eba27](d3eba27))

### Features

* **YouTube - Theme:** Disable gradient loading screen ([fd09e46](fd09e46))
* **YouTube:** Add `Announcements` patch ([#503](#503)) ([59687f1](59687f1))
* **YouTube:** Add `Spoof device dimensions` patch ([16f1163](16f1163))

### Performance Improvements

* **YouTube:** Reduce memory requirement for prefix tree searching ([#501](#501)) ([f5add51](f5add51))
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant