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

Improve performance of hybrid encrypt CLI #1483

Merged
merged 2 commits into from
Dec 7, 2024

Conversation

akoshelev
Copy link
Collaborator

There were quite a few bottlenecks here:

  • Writes were done serially, writing one file at a time.
  • Shares were encrypted on a single CPU core

I almost used rayon to parallelize encryption, but the problem is that we need to get the output sorted to maintain total order across files. Rayon can do that, but requires collecting ParallelIterator which would be bad for generating 100M+ reports.

Our goal is to be able to share and encrypt 1B, so streaming and manual fiddling with thread pools is justified imo.

The way this CLI works right now: it keeps a compute pool for encryption (thread-per-core) and a separate pool of 3 threads to write data for each helper in parallel

I also made a few tweaks to improve code re-usability in this module.

Benchmarks

Time it takes to encrypt 1M reports done locally on M1 Mac Pro (10 cores)

Before this change:
Encryption process is completed. 442.15834075s

After this change
Encryption process is completed. 55.63269625s

There were quite a few bottlenecks here:
* Writes were done serially, writing one file at a time.
* Shares were encrypted on a single CPU core

I almost used `rayon` to parallelize encryption, but the problem is that we need to get the output sorted to maintain total order across files. Rayon can do that, but requires collecting `ParallelIterator` which would be bad for generating 100M+ reports.

Our goal is to be able to share and encrypt 1B, so streaming and manual fiddling with thread pools is justified imo.

The way this CLI works right now: it keeps a compute pool for encryption (thread-per-core) and a separate pool of 3 threads to write data for each helper in parallel

I also made a few tweaks to improve code re-usability in this module.

## Benchmarks
Done locally on M1 Mac Pro (10 cores)

Before this change:
Encryption process is completed. 442.15834075s

After this change
Encryption process is completed. 55.63269625s
Copy link

codecov bot commented Dec 7, 2024

Codecov Report

Attention: Patch coverage is 96.79487% with 5 lines in your changes missing coverage. Please review.

Project coverage is 93.27%. Comparing base (e667e78) to head (1d44fc9).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
ipa-core/src/cli/crypto/hybrid_encrypt.rs 96.24% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1483      +/-   ##
==========================================
- Coverage   93.37%   93.27%   -0.10%     
==========================================
  Files         239      239              
  Lines       43476    43675     +199     
==========================================
+ Hits        40594    40739     +145     
- Misses       2882     2936      +54     

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

)
})
.collect(),
next_worker: 0,
Copy link
Member

Choose a reason for hiding this comment

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

why is next_worker always 0? what's the point of it if it's constant?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

mutation occurs inside encrypt_share

@eriktaubeneck eriktaubeneck merged commit b27a4b3 into private-attribution:main Dec 7, 2024
13 checks passed
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.

2 participants