On Sat, 26 Apr 2025 16:44:26 GMT, fabioromano1 <d...@openjdk.org> wrote:

>> This PR optimizes `BigInteger.pow(int)` method. The primary enhancement in 
>> `pow()` is not concerned most on execution time, but rather in memory 
>> optimization, because the PR implementation does the "shift of the exponent" 
>> squaring the result rather than the base, so the base is not squared like in 
>> the current implementation, and this permits to save about half of the 
>> memory.
>
> fabioromano1 has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Removed  method used by nth-root

src/java.base/share/classes/java/math/BigInteger.java line 2721:

> 2719:             if (!pow.equals(ONE)) {
> 2720:                 for (int i = 0; i < blockLen; i++)
> 2721:                     pow = pow.multiply(pow);

Majority of the time we have `blockLen == maxExpLen`. We should cache that 
pow-to-maxExpLen result too, if we have `maxExpLen >= nLen` initially. Maybe 
also calculate power-to-`nLen % maxExpLen` as that will be used in the final 
round of the loop.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/24690#discussion_r2061496813

Reply via email to