diff --git a/Lib/_pylong.py b/Lib/_pylong.py index 1ff9afed89b9e4..613085eaee9992 100644 --- a/Lib/_pylong.py +++ b/Lib/_pylong.py @@ -269,7 +269,12 @@ def inner(a, b): del defaultdict def _dec_str_to_int_inner(s, *, GUARD=8): - BYTELIM = 512 + # Yes, BYTELIM is "large". Large enough that CPython will usually + # use the Karatsuba _str_to_int_inner to convert the string. This + # allowed reducing the cutoff for calling _this_ function from 3.5M + # to 2M digits. We could almost certainly do even better by + # fine-tuning this and/or using a larger output base than 256. + BYTELIM = 100_000 D = decimal.Decimal result = bytearray() # See notes at end of file for discussion of GUARD. @@ -389,7 +394,7 @@ def int_from_string(s): # contain underscores and have trailing whitespace. s = s.rstrip().replace('_', '') func = _str_to_int_inner - if len(s) >= 3_500_000 and _decimal is not None: + if len(s) >= 2_000_000 and _decimal is not None: func = _dec_str_to_int_inner return func(s) diff --git a/Lib/test/test_int.py b/Lib/test/test_int.py index b865e4e396e853..67c080117edcc3 100644 --- a/Lib/test/test_int.py +++ b/Lib/test/test_int.py @@ -938,8 +938,8 @@ def test_whitebox_dec_str_to_int_inner_failsafe(self): # wrong about that. We have no input that reaches that block. # Here we test a contrived input that _does_ reach that block, # provided the number of guard digits is reduced to 1. - sn = "6" * (4000000 - 1) - n = (10**len(sn) - 1) // 9 * 6 + sn = "9" * 2000156 + n = 10**len(sn) - 1 orig_spread = _pylong._spread.copy() _pylong._spread.clear() try: