Skip to content
Advertisement

Java BigInteger alternative

Is there a way to improve BigInteger performance with caching?

When you operate on BigInteger it always creates a new BigInteger. For example, when you multiply two big integers, a new BigInteger is created to host the result. I want to use some mutable version of a BigInteger that will update one of the fields with the result.

Advertisement

Answer

There are mutable “versions” of BigInteger out there (e.g: https://github.com/bwakell/Huldra ) Or you can roll your own. Using a mutable object may reduce the pressure on the GC. You really should benchmark your application to see if this is worth the effort.

Advertisement