Skip to content

Speed up crypto library unit tests#466

Closed
kaczmarczyck wants to merge 1 commit intogoogle:developfrom
kaczmarczyck:crypto-test-speedup
Closed

Speed up crypto library unit tests#466
kaczmarczyck wants to merge 1 commit intogoogle:developfrom
kaczmarczyck:crypto-test-speedup

Conversation

@kaczmarczyck
Copy link
Copy Markdown
Collaborator

Local testing (run_desktop_tests.sh) is unnecessarily slow, in part because of the slow unit tests in the crypto library. Some unit tests took over a minute to complete.

This PR reduces the number of iterations for these tests. No test should take longer than a second. --report-time helps finding slow tests. This PR is a 50x reduction in CPU load for these tests.

Before:

$ time cargo test --features=std  -- -Zunstable-options --report-time
...
real	2m10.315s
user	12m6.005s
sys	0m2.419s

After:

$ time cargo test --features=std  -- -Zunstable-options --report-time
...
real	0m5.148s
user	0m13.719s
sys	0m0.100s

@kaczmarczyck kaczmarczyck requested a review from ia0 April 25, 2022 14:18
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.9%) to 88.627% when pulling 34f7737 on kaczmarczyck:crypto-test-speedup into 2b64243 on google:develop.

@kaczmarczyck
Copy link
Copy Markdown
Collaborator Author

Similar to #465 , the coverage report only changed in that it correctly handles libraries/persistent_store/src/store.rs now.

Copy link
Copy Markdown
Member

@ia0 ia0 left a comment

Choose a reason for hiding this comment

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

I understand the motivation for this, but I'm not sure this is the right solution at the moment. Here are some thoughts:

  • We want tests to be fast. This PR does it.
  • We want to thoroughly test the crypto. This PR reverts some of this. It would be fine if we had fuzzing. (Those test targets are essentially fuzzing targets.)

I see 2 options if we want to address desktop tests running time:

  • This PR followed by crypto fuzzing in a short time span.
  • Remove crypto tests from desktop tests (the tests still run on github workflows), take time to add crypto fuzzing, finally this PR (or even just delete the tests that are subsumed by fuzzing, unit tests should be concrete cases, not loops).

@@ -1005,7 +1005,10 @@ pub mod test {
fn test_scalar_base_mul_is_scalar_mul_generator() {
let gen = precomputed(0, 0);
// TODO: more scalars
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe remove those TODOs? Since the PR does the opposite.

for i in 0..512 {
for j in i..512 {
for i in (0..512).step_by(16) {
for j in (i..512).step_by(16) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why step 16 here? The idea of the test is to test slices of different sizes. I would use 3 and 5 (or 13 and 17 if we want bigger numbers)

@kaczmarczyck
Copy link
Copy Markdown
Collaborator Author

Closed for #467.

@kaczmarczyck kaczmarczyck deleted the crypto-test-speedup branch April 26, 2022 13:17
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.

3 participants