Skip to content

Reduce BigInteger construction#9292

Merged
headius merged 2 commits intojruby:jruby-10.0from
headius:time_rational_subseconds_tweaks
Mar 28, 2026
Merged

Reduce BigInteger construction#9292
headius merged 2 commits intojruby:jruby-10.0from
headius:time_rational_subseconds_tweaks

Conversation

@headius
Copy link
Copy Markdown
Member

@headius headius commented Mar 4, 2026

The numerator and denominator need to be BigInteger, so request them as such and reuse those instances. This reduces the number of BigIntegers constructed to four in the case where they are both already RubyBignum instances and numerator is less than denominator, and eight in the worst case where neither of them are RubyBignum instances and numerator is greater than denominator.

Previously, the best case was six BigInteger (extra from numerator and denominator being recreated).

The numerator and denominator need to be BigInteger, so request
them as such and reuse those instances. This reduces the number of
BigIntegers constructed to four in the case where they are both
already RubyBignum instances and numerator is less than
denominator, and eight in the worst case where neither of them are
RubyBignum instances and numerator is greater than denominator.

Previously, the best case was six BigInteger (extra from numerator
and denominator being recreated).
@headius headius added this to the JRuby 10.0.5.0 milestone Mar 4, 2026
If numerator == denominator, we don't need to do any of this math
and can avoid constructing any objects.
@headius headius merged commit d6d4709 into jruby:jruby-10.0 Mar 28, 2026
84 checks passed
@headius headius deleted the time_rational_subseconds_tweaks branch March 28, 2026 17:06
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.

1 participant