Repository navigation
Conversation
Contributor
Author
|
@KosherJava I am going to leave this PR here for your review. It really is not that big of a deal if you do not merge it, but I had Claude review why my app was running so slowly and this was it's findings. Apparently, this only affects debug android APKs so a release will be just as fast as the regular Math.fma method, but Android for some reason uses a 20x slower method on debug builds and other devices. Please review, and let us know if you are comfortable with this change or if anything else needs to change for the PR. |
Elyahu41
force-pushed
the
fix/spa-fma-performance
branch
from
November 15, 2026 18:57
d4c23a0 to
83102d5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Android, Math.fma is not always done by the hardware. In debuggable apps (debug builds) and on x86 and x86_64 devices (emulators, Chromebooks), ART runs the Java fallback instead: a BigDecimal multiply and add, with several allocations per call. The nutation series calls it about 580 times per solar position, so the SPA calculator was very slow there. Release builds on arm64 phones were not affected: on a Galaxy S23 (Android 16) ART uses the hardware instruction.
SPACalculator.fma is now Boldo and Melquiond's proven FMA emulation (Dekker's exact product, TwoSum, then rounding to odd), which is bit for bit the same as Math.fma. Inputs outside its proven range still go to Math.fma. The nutation also uses plain arithmetic where the product is already exact (multipliers 0, +-1 and +-2, and zero coefficients), which gives identical results.
Results are unchanged: 236,670 rise, set, noon, midnight, azimuth and position values from 10 locations over 1990-2059 are bit for bit identical before and after, on the desktop JVM and on ART (Galaxy S23, Android 16). 180 million fma cases, including exact ties and heavy cancellation, match Math.fma exactly. A test covers this.
Three days of zmanim with a fresh calculator: