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

filter: Improve speed of checking duplicates #1466

Merged
merged 2 commits into from
May 17, 2024

Conversation

victorlin
Copy link
Member

@victorlin victorlin commented May 17, 2024

Description of proposed changes

pandas's isin(set) converts the set into a list, making each value check scale linearly with the size of the set. In the usage here, it's unfortunate because the size of the set grows with each metadata chunk processed. That means the entire operation scales with (size of chunk * size of metadata).

Do the equivalent but much faster by first making a set from the current chunk's index then intersecting that with the set of previously seen IDs. This is faster because both of these steps scale linearly with the size of the chunk, not the size of the metadata, meaning the entire operation scales with (2 * size of chunk).

Related issue(s)

Checklist

pandas's isin(set) converts the set into a list, making each value check
scale linearly with the size of the set.¹ In the usage here, it's
unfortunate because the size of the set grows with each metadata chunk
processed. That means the entire operation scales with (size of chunk *
size of metadata).

Do the equivalent but much faster by first making a set from the current
chunk's index then intersecting that with the set of previously seen
IDs. This is faster because both of these steps scale linearly² with the
size of the chunk, not the size of the metadata, meaning the entire
operation scales with (2 * size of chunk).

¹ <pandas-dev/pandas#25507>
² <https://wiki.python.org/moin/TimeComplexity#set>
@victorlin victorlin self-assigned this May 17, 2024
@victorlin victorlin marked this pull request as ready for review May 17, 2024 19:30
@victorlin victorlin requested a review from a team May 17, 2024 19:30
Copy link

codecov bot commented May 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.85%. Comparing base (e0f88ca) to head (4923408).
Report is 240 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1466      +/-   ##
==========================================
+ Coverage   68.82%   68.85%   +0.03%     
==========================================
  Files          69       69              
  Lines        7595     7607      +12     
  Branches     1860     1861       +1     
==========================================
+ Hits         5227     5238      +11     
  Misses       2086     2086              
- Partials      282      283       +1     

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

@huddlej
Copy link
Contributor

huddlej commented May 17, 2024

Nice one, @victorlin!

@victorlin victorlin merged commit c241569 into master May 17, 2024
20 checks passed
@victorlin victorlin deleted the victorlin/faster-duplicate-check branch May 17, 2024 22:08
@trvrb
Copy link
Member

trvrb commented May 18, 2024

Very clever improvement. Thanks @victorlin!

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.

4 participants