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

Performance Optimization: Expanding binary search window #231

Merged
merged 7 commits into from
Jun 21, 2024

Conversation

benbrandt
Copy link
Owner

Optimizes the binary search to not be too greedy when checking the size of sections.

Previously, I relied on the fact that we'd find a semantic level that didn't fit in the chunk size. However, it is quite likely there won't be one, and then the reliance on having this to scope the sections we are binary searching over means that in worst case, we are binary searching over the entire rest of the document, which might be large search area, and requires tokenizing huge chunks of text, which is the real bottleneck.

Now, we increase the search area by a factor of 2 each successful attempt, and also keep track of updating our starting low value for the binary search if we already know it is too low.

Copy link

codecov bot commented Jun 17, 2024

Codecov Report

Attention: Patch coverage is 98.26087% with 4 lines in your changes missing coverage. Please review.

Project coverage is 99.50%. Comparing base (b1b39d1) to head (26998f1).

Current head 26998f1 differs from pull request most recent head a38ded3

Please upload reports for the commit a38ded3 to get more accurate results.

Files Patch % Lines
src/splitter.rs 96.33% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #231      +/-   ##
==========================================
- Coverage   99.65%   99.50%   -0.15%     
==========================================
  Files          11       11              
  Lines        2047     2033      -14     
==========================================
- Hits         2040     2023      -17     
- Misses          7       10       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Optimizes the binary search to not be too greedy when checking the size of sections.

Previously, I relied on the fact that we'd find a semantic level that didn't fit in the chunk size. However, it is quite likely there won't be one, and then the reliance on having this to scope the sections we are binary searching over means that in worst case, we are binary searching over the entire rest of the document, which might be large search area, and requires tokenizing huge chunks of text, which is the real bottleneck.

Now, we increase the search area by a factor of 2 each successful attempt, and also keep track of updating our starting `low` value for the binary search if we already know it is too low.
It turns out this didn't hold up with tokenization (surprise surprise) and also is replaced by the more optimistic binary search window search in previous commit.
@benbrandt benbrandt force-pushed the perf-optimization branch from 709938e to 26998f1 Compare June 21, 2024 20:05
@benbrandt benbrandt linked an issue Jun 21, 2024 that may be closed by this pull request
@benbrandt benbrandt merged commit 7c3cbbd into main Jun 21, 2024
21 checks passed
@benbrandt benbrandt deleted the perf-optimization branch June 21, 2024 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Heuristics for very large documents
1 participant