-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to define custom MP_MIN_DIGIT_COUNT. #569
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I didn't think of that before and I believe immediately that this can hit performance.
Still I'm not sure whether that's the best approach!
There are two places where MP_MIN_DIGIT_COUNT
are used, mp_init_size()
and mp_shrink()
. And mp_init_size()
is the one that is used throughout the library.
Wouldn't it make more sense to change
Line 13 in 8314bde
size = MP_MAX(MP_MIN_DIGIT_COUNT, size); |
MP_DEFAULT_DIGIT_COUNT
instead?
Like that we could still shrink to the real minimum size and whenever mp_init_size()
is called with a size < MP_DEFAULT_DIGIT_COUNT
it would at least alloc that.
What do you think? That proposed modification should have the same results, right?
Also please squash fixup commits.
Hey there. I went the way of allowing a custom My aim was to have libtommath with the least reallocations possible and with ints of a fixed size essentially. This is because I saw that the occasional With both the default and min digit count set to a sensible value (>= 2*field size for our ECC use case) we get way less reallocations and have more of fixed-size ints (though not really). I am of course open to any change that gets this, I just don't want to be intrusive to other users of this library that might not want something like this. |
@czurnieden your opinion on this? |
A custom Otherwise: yes, good idea, has my support. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please rebase on top of develop and squash those two commits.
48a3518
to
6dbb6fe
Compare
Basically, some internal functions ignore
MP_DEFAULT_DIGIT_COUNT
and allocate much smaller, which then reads to reallocations quite a bit.Allowing a custom
MP_MIN_DIGIT_COUNT
is nice when one wants to save reallocations, also related to constant-timeness a bit (#567).