From b0c1a31961e74c093e90626e030fa856d6c6e1fb Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 15 Jan 2026 14:46:00 +0900 Subject: [PATCH] mruby-bigint: raise Toom-3 threshold from 50 to 100 limbs Benchmarks show the previous threshold of 50 was too low, causing Toom-3's setup overhead to outweigh its asymptotic benefits for medium-sized numbers. Raising to 100 limbs provides: - 2x faster at 300 limbs (192 -> 96 us) - 2.5x faster at 120 limbs (42 -> 17 us) - 2.6x faster at 80 limbs (31 -> 12 us) Co-authored-by: Claude --- mrbgems/mruby-bigint/core/bigint.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index 6f48a7c4f..c771986bd 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -972,7 +972,7 @@ mpz_sqr_basic_limbs(mp_limb *result, const mp_limb *x, size_t n) * - Interpolate to recover result coefficients */ -#define TOOM3_THRESHOLD 50 +#define TOOM3_THRESHOLD 100 static inline mrb_bool should_use_toom3(size_t n)