-
Notifications
You must be signed in to change notification settings - Fork 17
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
BigDecimal parser #24
Comments
Yeah, should be feasible. 🤔 |
I am working on it. 😅 So far, the code in the dev-Branch is able to parse BigDecimals that have a significand of up to 536,870,919 digits. However, a BigDecimal can have up to 1,292,782,621 digits. |
I have now substantially refactored the code. It supports now BigDecimals with up to 1,292,782,621 digits. The code uses 4 different algorithms:
The API is provided by static methods in the class JavaBigDecimalParser.
I have made different versions of the code that take advantage of new JDK features. The code still needs more testing, and some cleanup. The performance should be at least the same as BigDecimal. On the java19 branch, I get the following results with the test file
|
I am still finding bugs in the code, so please use it for evaluation & testing only. I am pondering whether the JavaBigDecimalParser class should provide separate methods for single-threaded parsing and multi-threaded parsing. Multi-threaded parsing is about twice as fast, but requires a lot more memory. For this reason, in the Java API they decided to provide two different multiplication methods for BigInteger: BigIntgeger.multiply() Do you have any thoughts on this? |
In jackson-core, the fast number parsing is not the default - standard JRE number parsing is used - we will continue to warn users about potential differences when using fast parsers. Parallel thread parsing sounds generally useful but I suspect that it is not a priority on the jackson side. If you do add the support, we will consider supporting it. |
Is there a need for the non-throwing parser methods? These methods return null instead of throwing a NumberFormatException. The exception is very helpful for debugging. |
@wrandelshofer for the jackson-core use case, NumberFormatException is best solution for invalid inputs - we currently use JRE classes and would like the new parser code to behave similarly. I can see the benefit of having alternative methods that do not throw exceptions. Exceptions are expensive (generating the stacktrace, etc). |
I have removed the non-throwing code. Debugging the code is very hard without having exceptions with stack trace. |
The |
Here is a performance comparison showing the speedup with parallel parsing against non-parallel parsing. The times are given in nanoseconds.
The performance is exponential to the number of digits N: O(e^N) EDIT 2022-12-23 In the trendlines, x is computed as follows: x = log10(#Digits) + 1 |
@wrandelshofer I'm using v0.5.2 and have found that Would it be possible to support being able to disable hex support? |
I am closing this issue, because there is now a BigDecimal parser in this project. 😊 |
Thanks for all the hard work on the double and float parsers. Would there be any chance that you could consider adding support for BigDecimal parsing? A lot of the low level parser could be reused.
The text was updated successfully, but these errors were encountered: