Thursday, October 21, 2010

Probably you know that Nellymoser audio codec was contributed (both Java and C++) by UAB "DKD" (dkd.lt) and available on ffmpeg site (http://www.ffmpeg.org/, June 16 2008).

I decided to optimize Java code performance :)
and prepared (or found) Nellymoser encoded audio stream that is decoded/encoded 40 times (i.e. overall stream duration is 1230 seconds).

Initial implementation performs the task in ~5500ms.

First optimization step is to avoid too many "new float[]" - So a number of state float arrays are initialized in the very beginning and passed as a parameters to the respective methods.

As a result the task is executed in ~5250ms (95.5% of 5500ms).

The second optimization step is not obvious, but it is necessary if you want to port available code to J2ME. J2ME API doesn't have Math.pow(*) method, so it is necessary to replace Math.pow(2, *) with something. Something can be approximation by Taylor Series.

As a result: ~4100ms (74.6% of 5500ms)
Possible reason: Math.pow() is native method that is used very intensively by initial implementation.

Tests are performed on Athlon 64 X2 Dual, 3800+

No comments:

Post a Comment