Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Digging around for a faster implementation for BigInteger and BigDecimal

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 .gitignore
Octocat-spinner-32 README.md
Octocat-spinner-32 build.gradle
Octocat-spinner-32 settings.gradle
Octocat-spinner-32 thoughts.tex
README.md

FastBig

FastBig is a JVM library which is attempting to provide a faster drop-in replacement for java.math.BigInteger and java.math.BigDecimal. The current approach is:

  1. A tiny version which simply provides a single implementation for BigInteger and BigDecimal with deprecated stuff removed, based on long[] instead of int[] (assume a 64 bit world), and any other tweeks we can make to eke out a bit more performance.

    • The core libs working group are not dummies. They've got a pretty good impl already kicking around, so I don't have a whole lot of hope for the tiny version to actually be that much faster...
  2. A full version with more classes, leveraging type information to route to optimized versions and provide specialized implementation. So, for instance, there would be a FZero type that would simply return this when calling multiply or negate. I think this will give us substantial JIT

    • On this point, it's important to note that code is routed based on the parameter's compile-time type, not their run-time type. This can become an annoying run-around for what could be useful optimizations.
  3. One possibility for both versions to generate the optimized version at the bytecode level via ByteScript. This might give us just a bit more edge over the Java compiler, and it also opens up invokedynamic, which is the golden hammer of JDK7.

We don't yet know if either approach is actually faster than java.math.BigInteger. If they're not, that's interesting, too.

Testing

This is tested using Google Caliper on a self-compiled Mac port of OpenJDK 7, build 23.0-b12. To run the tests yourself, you will have to install caliper on your system, which involves downloading the files and running Maven according to their README. The only tip I have is that when you get into the starting measured section/done measured section loop, it will seem like your computer hung or entered an infinite loop or something, but just let it go. It will eventually end.

License

This code is based off the OpenJDK 8 versions of java.math.BigInteger and java.math.BigDecimal, which means that it is all licensed under the GPLv2.

Something went wrong with that request. Please try again.