[issue46361] Small ints aren't always cached properly

2022-01-16 Thread Mark Dickinson
Change by Mark Dickinson : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue46361] Small ints aren't always cached properly

2022-01-16 Thread Mark Dickinson
Mark Dickinson added the comment: New changeset 5cd9a162cd02a3d0f1b0a182d80feeb17439e84f by Brandt Bucher in branch 'main': bpo-46361: Fix "small" `int` caching (GH-30583) https://github.com/python/cpython/commit/5cd9a162cd02a3d0f1b0a182d80feeb17439e84f --

[issue46361] Small ints aren't always cached properly

2022-01-13 Thread Brandt Bucher
Brandt Bucher added the comment: The attached PR doesn't seem to have any impact on Decimal performance (non-optimized, non-debug build on a fairly quiet laptop): main: Convert 262,000 Decimals to "small" ints: 31.7 ms +- 5.3 ms Convert 256,000 Decimals to 1-digit ints: 29.9 ms +- 3.1 ms

[issue46361] Small ints aren't always cached properly

2022-01-13 Thread Brandt Bucher
Change by Brandt Bucher : -- keywords: +patch pull_requests: +28781 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30583 ___ Python tracker ___

[issue46361] Small ints aren't always cached properly

2022-01-13 Thread Mark Dickinson
Mark Dickinson added the comment: And there are some similar things going on in rangeobject.c. https://github.com/python/cpython/blob/1de60155d5d01be2924e72fb68dd13d4fd00acd7/Objects/rangeobject.c#L598 if (r->step == _PyLong_GetOne()) { return idx; } Again,

[issue46361] Small ints aren't always cached properly

2022-01-13 Thread Mark Dickinson
Mark Dickinson added the comment: Hmm. This sort of thing is a little dodgy, though (despite the comment that it's "okay"): https://github.com/python/cpython/blob/1de60155d5d01be2924e72fb68dd13d4fd00acd7/Modules/mathmodule.c#L939 PyObject *zero = _PyLong_GetZero(); // borrowed ref

[issue46361] Small ints aren't always cached properly

2022-01-13 Thread Mark Dickinson
Mark Dickinson added the comment: I don't *think* we currently rely on small integers being cached anywhere in the implementation (and neither do we guarantee anywhere in the docs that small integers will be cached), so as far as I can tell these omissions shouldn't lead to user-visible

[issue46361] Small ints aren't always cached properly

2022-01-12 Thread Raymond Hettinger
Change by Raymond Hettinger : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue46361] Small ints aren't always cached properly

2022-01-12 Thread Brandt Bucher
New submission from Brandt Bucher : To my surprise, it seems that it's possible to create "small" integers that should live in _PyLong_SMALL_INTS, but don't. Here are two examples I've found: >>> import decimal >>> i = int(decimal.Decimal(42)) # Modules/_decimal/_decimal.c:dec_as_long >>> i