-
Notifications
You must be signed in to change notification settings - Fork 21
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
Use libj.math.BigInt
for arithmetic
#15
base: main
Are you sure you want to change the base?
Conversation
Java's built-in `BigInteger` class is a solid platform for building out programs that require the use of arbitrarily-sized numbers. However, when it comes to improving performance, `BigInteger` can become problematic for the following reasons: - While it has been optimized over the years, it does not deliver optimal performance for certain mathematical operations - It only has immutable semantics (i.e. any mathematical operation on a `BigInteger` will allocate and return a *new* `BigInteger`), which leads to unavoidable memory pressure at scale. This commit replaces `BigInteger` with libj's `BigInt` class, which uses a value-encoding scheme to deliver faster operations and mutable behavior which allows for improving memory footprint. This change delivers a 45% improvement in the current benchmark suite on a 16GB Macbook M1 Pro: ``` Benchmark Mode Cnt Score Error Units FF3CipherPerf.testEncrypt thrpt 5 97629.798 ± 2972.249 ops/s Benchmark Mode Cnt Score Error Units FF3CipherPerf.testEncrypt thrpt 5 178592.429 ± 3097.461 ops/s ``` This commit introduces [`libj.math.BigInt`](https://mvnrepository.com/artifact/org.libj/math/0.6.8) as a project dependency.
@altr-benjamin What's the need for maven.repository.redhat.com in build.gradle.kts? libj is available MavenCentral (https://mvnrepository.com/artifact/org.libj/math). |
Without |
Does libj:match mention this dependency? Do they have a plan going forward to replace it? I filed #59 for this.
(original) (with libj:math patch) Benchmark Mode Cnt Score Error Units |
@bschoening In order:
|
@altr-benjamin seems it may take a while to resolve the unnecessary diff_match_patch dependency. Given this, I'm considering making a new release of java-fpe which would include the String the char array changes. Let me know if you would find that useful. The discussion on libj has highlighted some of the downsides of hardwiring in lesser known 3rd party libraries maintained by a sole individual. I'm wondering if we can make this pluggable with a factory provider, the way SLF4J works. |
@bschoening if you'd like to cut a new release with the char array changes that's fine by me -- any perf improvement is welcome there. Good point and interesting comment on the pluggable pattern! IMO the big difference b/w BigInteger and libj is the mutability, but I'd be happy to take that to the drawing board and see if it could be abstracted out enough to be workable. |
@altr-benjamin BigInteger is immutable for thread safety. But I don't see that as needed in a Feistel cipher. |
Java's built-in
BigInteger
class is a solid platform for building out programs that require the use of arbitrarily-sized numbers. However, when it comes to performance optimization,BigInteger
can become problematic for the following reasons:BigInteger
will allocate and return a newBigInteger
), which leads to unavoidable memory pressure at scale.This commit replaces
BigInteger
with libj'sBigInt
class, which uses a value-encoding scheme to deliver faster operations and mutable behavior which allows for improving memory footprint.This change delivers a 45% improvement in the current benchmark suite on a 16GB Macbook M1 Pro:
This commit introduces
[email protected]
as a project dependency.