Skip to content

Extend static B_int allocation to -128#2492

Merged
plajjan merged 1 commit into
mainfrom
static-allocate-negative-int
Oct 25, 2025
Merged

Extend static B_int allocation to -128#2492
plajjan merged 1 commit into
mainfrom
static-allocate-negative-int

Conversation

@mzagozen

Copy link
Copy Markdown
Collaborator

Extended the B_int_strs cache to include pre-allocated B_int instances for negative integers from -1 to -128 (8-bit signed). This avoids dynamic allocation, and by extension the GC, with the aim of improving performance.

Extended the B_int_strs cache to include pre-allocated B_int instances
for negative integers from -1 to -128 (8-bit signed). This avoids
dynamic allocation, and by extension the GC, with the aim of improving
performance.
@mzagozen

Copy link
Copy Markdown
Collaborator Author

Perhaps the range -1 .. -128 is too broad as the most common negative number returned from C is -1 (like from str.c, net.c). @sydow what do you think?

@plajjan

plajjan commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

Python does down to -5 and up to 256

>>> a = -6
>>> b = -6
>>> a is b
False
>>> a = -5
>>> b = -5
>>> a is b
True
>>> a = 256
>>> b = 256
>>> a is b
True
>>> a = 257
>>> b = 257
>>> a is b
False
>>>

@plajjan

plajjan commented Oct 24, 2025

Copy link
Copy Markdown
Contributor

From what I remember, there was a reason why we didn't do any negative numbers at all and started from 0 instead, but I can't remember why... @sydow @nordlander whyyyy??? :)

@nordlander

Copy link
Copy Markdown
Contributor

Sorry, no recollection…

@mzagozen

Copy link
Copy Markdown
Collaborator Author

Compared to the static B_bool change, this is statistically insignificant. Marking as draft, should reduce the range to -5.

@mzagozen mzagozen marked this pull request as draft October 24, 2025 20:27
@sydow

sydow commented Oct 25, 2025

Copy link
Copy Markdown
Collaborator

I see no problems and Marko's PR looks perfect. I would recommend merging it as it is.

@plajjan plajjan marked this pull request as ready for review October 25, 2025 14:13
@plajjan

plajjan commented Oct 25, 2025

Copy link
Copy Markdown
Contributor

Compared to the static B_bool change, this is statistically insignificant. Marking as draft, should reduce the range to -5.

but is this insignificant when you do .contains() or with .index()??

@plajjan plajjan merged commit bc39185 into main Oct 25, 2025
35 checks passed
@plajjan plajjan deleted the static-allocate-negative-int branch October 25, 2025 14:13
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.

4 participants