Repository navigation
Closes #5043: Investigate performance loss from negative bigint changes - #5044
Merged
ajpotts merged 1 commit intoDec 4, 2025
Conversation
1RyanK
force-pushed
the
5043-Investigate_performance_loss_from_negative_bigint_changes
branch
2 times, most recently
from
November 12, 2025 12:42
b920070 to
347aca5
Compare
1RyanK
force-pushed
the
5043-Investigate_performance_loss_from_negative_bigint_changes
branch
from
November 13, 2025 17:27
850b58d to
1fbf42c
Compare
ajpotts
reviewed
Nov 18, 2025
1RyanK
force-pushed
the
5043-Investigate_performance_loss_from_negative_bigint_changes
branch
4 times, most recently
from
November 20, 2025 16:13
2bb82f6 to
faee9c4
Compare
1RyanK
force-pushed
the
5043-Investigate_performance_loss_from_negative_bigint_changes
branch
3 times, most recently
from
December 1, 2025 17:30
f3e4f5a to
deeb252
Compare
1RyanK
force-pushed
the
5043-Investigate_performance_loss_from_negative_bigint_changes
branch
from
December 1, 2025 20:06
deeb252 to
7649045
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While PR #4985 technically fixed the issue of general negative bigint problems, it caused a performance regression. I believe this is primarily due to the overhead of creating the sign array. Instead, here's basically what happens in the code:
Then the code figures out how many times to pull off
uint64limbs, rather than waiting until everything is zero (which doesn't happen in the negative case, it just continues to be -1).The code runs out to
twothree separate Chapel functions depending on the case. If the input is just anint64oruint64array, it converts it directly to bigint (similar forfloat64or some other kind of floating point input). If the input is numpy's version of a bigint array, it goes to the multi-limb version (unfortunately, this is the case even if everything comes out to just one limb, but I think the performance loss here is not that bad). If the input data had any negative values, it treats the limbs as signed (all bits are positive and the top bit is negative). However, it's hard to create a bigint like this (AFAIK). So Chapel-side, it creates a signs array, strips off the top bit of every limb and treats it as a bool to reference later. Either way, it goes to the "Horner fold" step, which, as ChatGPT tells me, is possibly a faster way to create the bigints. Previously the code was bit shifting the limbs into the right spot and then adding them to the bigint value. The idea here is that you start with the highest limb of the data, then you bitshift it and add in the next limb, bitshift what you have and add in the next limb, and so on. You can read more about the generic version of this here (take x =2**64). Then it adds in the signed bit as necessary.It also handles the case where
max_bitsis not -1.Hopefully any loss in performance is made up by a few factors:
2**64and then integer dividing by the same value. I think it could speed the code up to do a bitmask by2**64 - 1and then bitshift by 64.int64oruint64data, it should go to the single limb version and that should run quicker.This also handles all cases of numeric data to bigint output in a single function, so if the performance is back up, then I can cut out some code in the array function.I went ahead and cut the old bigint code out.
Closes #5043: Investigate performance loss from negative bigint changes