From baef67dbb59281fcd9937bfc17a7463048426cfd Mon Sep 17 00:00:00 2001 From: Mario Rugiero Date: Thu, 27 Jul 2023 17:33:44 -0300 Subject: [PATCH] perf: replace asserts by debug_asserts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Runtime assertions to validate inputs were consuming a significant amount of time in benchmarks. Measured on an M1, based on branch `fix_felt_benchmarks` with the `ark-ff` code commented out to reduce noise we observe the following changes: ``` add | lambdaworks time: [12.273 µs 12.278 µs 12.285 µs] change: [-63.107% -63.042% -62.979%] (p = 0.00 < 0.05) Performance has improved. invert | lambdaworks time: [26.858 ms 26.864 ms 26.871 ms] change: [-7.8986% -7.8611% -7.8231%] (p = 0.00 < 0.05) Performance has improved. mul | lambdaworks time: [63.604 µs 63.622 µs 63.645 µs] change: [-0.1615% -0.0957% -0.0332%] (p = 0.00 < 0.05) Change within noise threshold. pow | lambdaworks time: [12.594 ms 12.599 ms 12.604 ms] change: [-0.4536% -0.4009% -0.3481%] (p = 0.00 < 0.05) Change within noise threshold. sqrt | lambdaworks time: [139.76 ms 139.79 ms 139.82 ms] change: [-0.1288% -0.1015% -0.0730%] (p = 0.00 < 0.05) Change within noise threshold. sub | lambdaworks time: [13.518 µs 13.529 µs 13.542 µs] change: [-19.474% -18.102% -17.059%] (p = 0.00 < 0.05) Performance has improved. ``` --- math/src/unsigned_integer/element.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/math/src/unsigned_integer/element.rs b/math/src/unsigned_integer/element.rs index 20e909429..4a79d9f6c 100644 --- a/math/src/unsigned_integer/element.rs +++ b/math/src/unsigned_integer/element.rs @@ -149,7 +149,7 @@ impl Sub<&UnsignedInteger> for &UnsignedInteg fn sub(self, other: &UnsignedInteger) -> UnsignedInteger { let (result, overflow) = UnsignedInteger::sub(self, other); - assert!(!overflow, "UnsignedInteger subtraction overflow."); + debug_assert!(!overflow, "UnsignedInteger subtraction overflow."); result } } @@ -804,7 +804,7 @@ impl UnsignedInteger { /// Computes self / rhs, returns the quotient, remainder. pub fn div_rem(&self, rhs: &Self) -> (Self, Self) { - assert!( + debug_assert!( *rhs != UnsignedInteger::from_u64(0), "Attempted to divide by zero" );