Zeroize performance on u8 arrays
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- rust
- Domain
- performance
Research direction
Start with the Rust Playground benchmark linked in the issue and inspect the generated assembly for zeroize on [u8; 32]. Compare the current output with the inline-assembly and larger-type approaches described in the report. Done requires an agreed optimization or documentation change, with its performance and code-size impact verified.
Written by the indexing model from the issue text.
Description
I inspected the generated assembly code and benchmarked zeroize for [u8; 32] on x86_64 and found it quite inefficient, storing one byte at a time:
On my Ryzen CPU, it takes ~7.8324 ns, or ~1cpb. Binary code size is also quite large.
Using inline assembly (just stabilized in 1.59) and SSE2, zeroing a [u8; 32] takes just 3 instructions and ~492.87 ps (~16 bytes per cycle):
let mut buf: [u8; 32];
core::arch::asm!(
"xorps {zero}, {zero}",
"movups {zero}, ({ptr})",
"movups {zero}, 16({ptr})",
zero = out(xmm_reg) _,
ptr = in(reg) &mut buf,
options(att_syntax, nostack, preserves_flags),
);
So it might be something worth optimizing/documenting.
If you do not want to use inline assembly, maybe you should encourage using larger types or SIMD types, e.g., [u64; 4] or [__m128; 2] instead of [u8; 32]. Using write_volatile on *mut __m128 generates equally compact and efficient code as the assembly code above.
- Dominant language
- Rust
- Stars
- 674
- Forks
- 170
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 10
Getting set up
We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from RustCrypto/utils
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
RustCrypto/utils#1546 · 1 comment ·
Maintainers usually reply within 2 days
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
RustCrypto/utils#1537 · 7 comments ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
RustCrypto/utils#1534 · 2 comments ·
Maintainers usually reply within 2 days
-
Difficulty 5/5 Over a week Newbie friendliness 45/100
RustCrypto/utils#1529 · 4 comments ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
RustCrypto/utils#1510 · 1 comment ·
Maintainers usually reply within 2 days
All issues in RustCrypto/utils
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Docs: "Work with Codex from anywhere" page still claims Windows mobile support is "coming soon"Openapp documentation remote windows-os
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
oxidecomputer/dendrite#380 ·
Maintainers usually reply within 5 days
-
area:cli bug good first issue priority:high
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day