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

Remove ArrayEncoding usage from Digest and delete ArrayEncoding. #1731

Merged
merged 2 commits into from
Nov 22, 2023

Conversation

briansmith
Copy link
Owner

No description provided.

@briansmith briansmith self-assigned this Oct 11, 2023
@codecov
Copy link

codecov bot commented Oct 11, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (1598583) 96.00% compared to head (149904c) 95.99%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1731      +/-   ##
==========================================
- Coverage   96.00%   95.99%   -0.02%     
==========================================
  Files         137      137              
  Lines       20749    20753       +4     
  Branches      226      226              
==========================================
+ Hits        19920    19921       +1     
- Misses        795      798       +3     
  Partials       34       34              

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

@briansmith
Copy link
Owner Author

I still need to benchmark this. Will add benchmarks for ring::digest in another PR.

@briansmith
Copy link
Owner Author

@joshlf This removes the last unsafe from ring::endian.

Copy link
Contributor

@joshlf joshlf left a comment

Choose a reason for hiding this comment

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

Nice!

src/digest.rs Show resolved Hide resolved
@briansmith
Copy link
Owner Author

This has been blocked on adding (back) the benchmarks for ring::digest to ensure this doesn't negatively affect performance. Those are in #1809 now.

Note: I originally tried an alternative implementation using `flat_map` that
ended up being materially slower. To fix that performance regression I had to
make the following change:

```
     let mut output = Output([0; MAX_OUTPUT_LEN]);
     output
         .0
-        .iter_mut()
-        .zip(input.iter().copied().flat_map(|Wrapping(w)| f(w)))
+        .chunks_mut(N)
+        .zip(input.iter().copied().map(|Wrapping(w)| f(w)))
         .for_each(|(o, i)| {
-            *o = i;
+            o.copy_from_slice(&i);
         });
     output
 }
```

I verified that this generates the same assembly code as the original code
on x86-64 using Rust 1.74.0, except that there are two additional 128-bit
moves in `sha256_formta_output` to zero out the latter half of `Output`,
which was intended.
@briansmith
Copy link
Owner Author

Using the benchmark added in PR #1809, I found that my original implementation here did have a notable performance regression. To fix it, I had to make this change:

     let mut output = Output([0; MAX_OUTPUT_LEN]);
     output
         .0
-        .iter_mut()
-        .zip(input.iter().copied().flat_map(|Wrapping(w)| f(w)))
+        .chunks_mut(N)
+        .zip(input.iter().copied().map(|Wrapping(w)| f(w)))
         .for_each(|(o, i)| {
-            *o = i;
+            o.copy_from_slice(&i);
         });
     output
 }

I verified that this generates the same assembly code as the original code on x86-64 using Rust 1.74.0, except that there are two additional 128-bit moves in sha256_formta_output to zero out the latter half of Output, which was intended.

@briansmith
Copy link
Owner Author

The codecov "project" coverage % "failure" is expected since this reduces the amount of covered code.

@briansmith briansmith merged commit 57fc486 into main Nov 22, 2023
137 of 138 checks passed
@briansmith briansmith deleted the b/digest-array-encoding branch November 22, 2023 17:35
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.

None yet

2 participants