Skip to content

math.big: optimize divide_array_by_digit() #24566

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

Merged
merged 1 commit into from
May 25, 2025

Conversation

tankf33der
Copy link
Contributor

@tankf33der tankf33der commented May 24, 2025

Capacity for quotient array already defined in integer.v like this:

...
       // Division for positive integers
        mut q := []u32{cap: int_max(1, dividend.digits.len - divisor.digits.len + 1)}
        mut r := []u32{cap: dividend.digits.len}
        divide_digit_array(dividend.digits, divisor.digits, mut q, mut r)
...

so just use it instead of full operand_a.
One of the important clients of this function is str() function.
Everyone will feel the difference.

Performance improvements:

  • "./v test vlib/math/big/" works ~3+ times faster
  • str() on ~180k digits works ~6 times faster

Copy link

Connected to Huly®: V_0.6-22932

@enghitalo
Copy link
Contributor

Good catch!

@spytheman
Copy link
Member

Excellent.

@spytheman spytheman merged commit f19e8a7 into vlang:master May 25, 2025
70 checks passed
ctkjose pushed a commit to ctkjose/vlang that referenced this pull request May 27, 2025
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.

3 participants