commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gilles (JIRA)" <>
Subject [jira] [Commented] (MATH-650) FastMath has static code which slows the first access to FastMath
Date Wed, 07 Sep 2011 22:49:09 GMT


Gilles commented on MATH-650:

IIUC, only the initializations needed by a method call are performed.
Thus "max" has become fast because it doesn't need any of those data arrays.

For those methods that need the data, one has to compare the startup times between computing
the data and loading precomputed data. For methods that only need some of the data, the time
gain might not be worth trailing the huge precomputed arrays.

If several calls are made to methods that need most of the data arrays, the initialization
time will be increasingly negligible (with respect to the "useful" application running time).
Which again renders the precomputed arrays unnecessary.

So, in summary, lazy initialization is very nice, especially for short-lived applications
that happen to call methods that don't need the data at all.
It's still nice for applications that happen to need only part of the data.
It's useless for applications that will need all the data arrays. (But it probably does not
However, I still don't see an advantage in storing precomputed values. I don't think that
it should be adopted just for a toy application that would call a math function once and exit.

> FastMath has static code which slows the first access to FastMath
> -----------------------------------------------------------------
>                 Key: MATH-650
>                 URL:
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: Nightly Builds
>         Environment: Android 2.3 (Dalvik VM with JIT)
>            Reporter: Alexis Robert
>            Priority: Minor
> Working on an Android application using Orekit, I've discovered that a simple FastMath.floor()
takes about 4 to 5 secs on a 1GHz Nexus One phone (only the first time it's called). I've
launched the Android profiling tool (traceview) and the problem seems to be linked with the
static portion of FastMath code named "// Initialize tables"
> The timing resulted in :
> - FastMath.slowexp (40.8%)
> - FastMath.expint (39.2%)
>  \- FastMath.quadmult() (95.6% of expint)
> - FastMath.slowlog (18.2%)
> Hoping that would help
> Thanks!
> Alexis Robert

This message is automatically generated by JIRA.
For more information on JIRA, see:


View raw message