Skip to content

bitlen: performance guesswork#1298

Merged
tarcieri merged 1 commit into
masterfrom
bitlen/performance-guesswork
Jun 21, 2026
Merged

bitlen: performance guesswork#1298
tarcieri merged 1 commit into
masterfrom
bitlen/performance-guesswork

Conversation

@tarcieri

Copy link
Copy Markdown
Member

This is an attempt to address #1296, although unfortunately it doesn't have a self-contained benchmark, and when I tried to run what's available it uses FFI and needs a bunch of external dependencies. I didn't futz with any of that and just tried throwing everything at the wall in this PR hoping one of the changes addresses the problem.

First, it sprinkles inline(always) on everything. While that's generally an antipattern, these functions are both deeply nested and incredibly trivial: usually just one or two wrapping arithmetic ops in release builds, and they're deep in hot paths, so really they need to get aggressively inlined.

Speaking of that, this also completely ditches checks/assertions in release builds for performance, whereas before they were always compiled in. That should keep the hot path incredibly simple.

None of this had any major impact on crypto-bigint's own benchmarks. The only change that seemed to be barely escaping the noise threshold was adding #[inline(always)] to UintRef::bits_precision which seemed to eek out some ~1.8% cross-cutting performance improvements, though I didn't check to see if they're reproducible and that's pretty much within the noise threshold so don't quote me on that.

Hopefully one of these changes addresses the situation in #1296.

This is an attempt to address #1296, although unfortunately it doesn't
have a self-contained benchmark, and when I tried to run what's
available it uses FFI and needs a bunch of external dependencies. I
didn't futz with any of that and just tried throwing everything at the
wall in this PR hoping one of the changes addresses the problem.

First, it sprinkles `inline(always)` on everything. While that's
generally an antipattern, these functions are both deeply nested and
incredibly trivial: usually just one or two wrapping arithmetic ops in
release builds, and they're deep in hot paths, so really they need to
get aggressively inlined.

Speaking of that, this also completely ditches checks/assertions in
release builds for performance, whereas before they were always compiled
in. That should keep the hot path incredibly simple.

None of this had any major impact on `crypto-bigint`'s own benchmarks.
The only change that seemed to be barely escaping the noise threshold
was adding `#[inline(always)]` to `UintRef::bits_precision` which seemed
to eek out some ~1.8% cross-cutting performance improvements, though I
didn't check to see if they're reproducible and that's pretty much
within the noise threshold so don't quote me on that.

Hopefully one of these changes addresses the situation in #1296.
@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 91.31%. Comparing base (fc6fc86) to head (4979c0d).

Files with missing lines Patch % Lines
src/bitlen.rs 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1298      +/-   ##
==========================================
- Coverage   91.31%   91.31%   -0.01%     
==========================================
  Files         190      190              
  Lines       22544    22546       +2     
==========================================
+ Hits        20587    20588       +1     
- Misses       1957     1958       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tarcieri tarcieri merged commit 7eb0a4b into master Jun 21, 2026
32 checks passed
@tarcieri tarcieri deleted the bitlen/performance-guesswork branch June 21, 2026 14:25
@tarcieri tarcieri mentioned this pull request Jun 22, 2026
tarcieri added a commit that referenced this pull request Jun 22, 2026
## Added
- `BoxedUint::{from_be_slice_truncated, from_le_slice_truncated}` (#1266)
- `Encoding::{from_bytes, to_bytes}` (#1297)
- `Uint::{from_be_slice_truncated, from_le_slice_truncated}` (#1299)
- `Limb::{from_*_bytes, from_*_slice_truncated, to_*_bytes}` as
  `const fn`s (#1300)
- `Encoding::{from_be_slice_truncated, from_le_slice_truncated}` trait
  methods (#1301)
- `ArrayEncoding::{from_byte_array, to_byte_array}` (#1302)

## Fixed
- Preserve `NonZero` and `Odd` invariants in `Zeroize` impls (#1287)
- `bitlen` performance (#1298)
- `floor_sqrt` regression (#1304)
- Truncated Karatsuba carry (#1305)
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.

1 participant