RFR: 8355719: Reduce memory consumption of BigInteger.pow() [v46]
Raffaello Giulietti
rgiulietti at openjdk.org
Tue Apr 29 15:20:48 UTC 2025
On Tue, 29 Apr 2025 15:10:10 GMT, fabioromano1 <duke at 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 two additional commits since the last revision:
>
> - Adjust the type of operand
> - Use a more loose formula to do range check
>
> Use a more loose formula to do range check, in order not to exclude a priori values that may be inside the supported range
Thanks.
What went wrong before?
> Instead, when I try to run the tests with a custom JVM, unfortunately I get this Exception:
>
> Exception in thread "main" java.lang.RuntimeException: ERROR: Unable to find the resource: /META-INF/BenchmarkList
> at org.openjdk.jmh.runner.AbstractResourceReader.getReaders(AbstractResourceReader.java:98)
> at org.openjdk.jmh.runner.BenchmarkList.find(BenchmarkList.java:124)
> at org.openjdk.jmh.runner.Runner.internalRun(Runner.java:252)
> at org.openjdk.jmh.runner.Runner.run(Runner.java:208)
> at org.openjdk.jmh.Main.main(Main.java:71)
>
Some observations:
- You should really compare before/after on the otherwise same environment, here JDK 25-internal. Comparing JDK 21.0.7-ea (which is an early-access release) and JDK 25-internal might not be that meaningful. In the meantime there have been improvements in the runtime, GC, etc.
- AFAIU, your Linux OS runs in some virtualized environment (e.g., VirtualBox). It would be better to use some native installation, but I understand this is not always feasible.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/24690#issuecomment-2839315518
More information about the core-libs-dev
mailing list