From 44d27a850e9a5c527cc79392d2017c1d5a6c8981 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 15 Nov 2026 13:56:49 -0500 Subject: [PATCH] SPACalculator: JavaDoc note on Math.fma speed on Android Math.fma is not always done by the hardware on Android. In debuggable apps and on x86 and x86_64 devices ART can run the BigDecimal fallback, which makes the nutation series (about 580 calls per solar position) much slower there. Release builds on arm64 and the desktop JVM are not affected. Document this so others know, and point to NOAACalculator and MeeusCalculator as alternatives. No code changes. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_015Er4SvtJRimfdZy8eVBECH --- .../com/kosherjava/zmanim/util/SPACalculator.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/com/kosherjava/zmanim/util/SPACalculator.java b/src/main/java/com/kosherjava/zmanim/util/SPACalculator.java index b08a4eaf..b4fb3486 100644 --- a/src/main/java/com/kosherjava/zmanim/util/SPACalculator.java +++ b/src/main/java/com/kosherjava/zmanim/util/SPACalculator.java @@ -69,6 +69,17 @@ * zmanim requirements. For the full published SPA ±0.0003° envelope, the VSOP87 tables and the IAU 1980 nutation series can * be extended without changing the algorithm. * + *

Performance note (Android). The nutation series calls {@link Math#fma(double, double, double)} about 580 times for each + * solar position. On the desktop JVM and on arm64 Android release builds this is a single hardware instruction, and three days of + * zmanim with a fresh calculator took about 1 - 12 ms in the measurements made for this note (a Galaxy S23 on Android 16). Android's + * runtime (ART) does not always do this, though. In debuggable apps (debug builds) and on x86 and x86_64 devices (emulators, + * Chromebooks) it can run the Java fallback of {@code Math.fma}, a {@link java.math.BigDecimal} multiply and add that allocates + * several objects per call. In the same measurements, three days of zmanim took about 200 - 1080 ms in a debug build on a Galaxy + * S23, and about 650 - 3100 ms on an Android 17 x86_64 emulator (not debuggable). The results are the same, only slower. If this + * matters for an app in those environments, test on a release build or on an arm64 device, use another {@link + * AstronomicalCalculator} such as {@link NOAACalculator} or {@link MeeusCalculator} (which do not use {@code Math.fma}), or create + * your own subclass of {@link AstronomicalCalculator}. + * * @author © Eliyahu Hershfeld 2026; NREL SPA (Reda and Andreas) port */ public class SPACalculator extends AstronomicalCalculator {