We have a library codebase that is being ported to Android. I've already ported it from Windows to iOS successfully. For some reason however the version built by the NDK is about 5-8x slower than the one built and run on my iPhone 5c. I recognize the slowness could simply be the device (a Samsung Galaxy S3) but the consensus here at our shop after discussions is that something else is the major cause.
I'm certain that ndk-build is generating a release version because it does that by default -- you have to explicitly make it do otherwise if desired, either by means of the make file or the command line.
It involves processing camera images, and I've gone so far as to completely stop the camera once it hands a frame to the library for processing. I was originally concerned that by improperly using the camera the Android was hogging resources to the extent that by the time the library methods were called the slowness was inevitable. But it's just a barebones app -- nothing going on but the normal display of camera frames and passing them to the library for processing (2 functions, although 2nd is quite extensive).
I'm generating timing information on a function level in the library -- the same methods are all executing slower, though not always 5-8x, sometimes only 3x.
No other apps are running on the device.
If it is very unlikely that it's simply slow hardware, I could use suggestions on how to attack this problem. Our CTO (a very bright, experienced guy) assures me the Galaxy S3 should be much closer to the iPhone 5 in performance. The source code is identical, only it was built with the NDK rather than Xcode or Developer Studio.
In onPreviewFrame() I launch the AsyncTask that simply makes the call(s) into the library. Some code:
@Override
public void onPreviewFrame(byte[] data, Camera camera)
{
if ((imageFormat == ImageFormat.NV21) && (!m_bProcessingInProgress))
{
if (data == null)
return;
m_bmpGrayScale = null;
m_bProcessingInProgress = true; // this indicates that we are processing a video frame
m_camera.stopPreview(); // halt camera while chewing on pixels
new ProcessPreviewDataTask().execute(data); // launch AsyncTask
}
else
{
if (data != null)
m_camera.addCallbackBuffer(data);
}
}