zeroize: remove internal use of optimization_barrier - #1535
Conversation
c788dab to
e8fa876
Compare
We replaced our previous use of compiler fences with `optimization_barrier` under the assumption it would be a zero-cost abstraction, but per #1504 that is not the case as it caused a performance regression. The use of either of these was effectively redundant and a belt-and-suspenders defense as volatile writes alone are already sufficient to guarantee zeroization will not be removed by the compiler. This removes the use of `optimization_barrier` to restore the previous performance. Closes #1504.
e8fa876 to
e4f62e9
Compare
Sorry, I was at rustconf. Here's some quick micro-benchmarks that represent rustls's use of this crate, over this PR: With that said, against a baseline impl on There appears to be a lot of scope in this crate to further improve performance. That could be achieved without abandoning volatile writes, if that is the firm desire of the maintainers. For example, |
Unfortunately, AFAIK it is not possible without specialization or breaking changes. |
|
For very common types, I think this can be achieved with a similar trick to Here's a prototype of this: ctz@e01ef4c (disclosure: slop). I don't plan to open a PR with this change, but it demonstrates the principle. The performance gain of this change on |
|
Note that |
|
We could potentially expose a This particular case was unfortunately running into some bad interactions between the (Sidebar: some upstream support from LLVM here would be nice) |
We replaced our previous use of compiler fences with
optimization_barrierunder the assumption it would be a zero-cost abstraction, but per #1504 that is not the case as it caused a performance regression.The use of either of these was effectively redundant and a belt-and-suspenders defense as volatile writes alone are already sufficient to guarantee zeroization will not be removed by the compiler.
This removes the use of
optimization_barrierto restore the previous performance.Closes #1504.