DrawScaledBitmap with xscale & yscale equal to 1.0f is unoptimized on both device as in simulator


I stumbled upon this by accident, as i wanted to make use of bitmapscaling but i assumed that in case xscale & yscale is 1.0f so basically no scaling needs to be done it would be as fast as just calling DrawBitmap but it clearly isn't at all. In fact there does not seem to be an optimized route done to call just DrawBitmap in case xscale & yscale equals 1.0f (no scaling needs to be done).

I tested this using a modified version of bunnymark on both the device as on the simulator and both exhibit the unoptimized handling. It would seem whatever is being done to draw scaled images is also being done in this special case.

To give you an idea these are the numbers i had gotten:

always the same image was used in these tests

drawing 10000 images with drawBitmap = 5 fps, fps starts dropping below 50 at around 7000 images, at 1000 images i'm still at 50 fps
drawing 10000 images with drawScaledBitmap = 2fps, fps starts dropping below 50 at around 1000 images when i get about 41-45 fps

drawing 1000 images with drawBitmap = 7 fps 100 images = 43 fps
drawing 1000 images with drawScaledBitmap = 2fps 100 images = 9 fps

source below
Source.zip (24.6 KB)

It seems to me these calls can be optimized internally...

I did not look at drawrotatedbitmap, but it's possible it contains the same problem in case yscale and xscale equal 1.0f and degrees equals 0 which is basically also drawing the original image

PS: i was running debug builds in both simulator and device using Latest SDK version 2.0.1 on windows, i did not test with release builds

The reason this is an issue is because now people will have to create such optimazation themselves in the code by calling just drawbitmap, while the api could normally do it or draw the image without applying any scaling (drawbitmap ?), some people might also think using drawscaledbitmap with 1.0f for both xscale and yscale would give equal speed as drawbitmap and in certain cases where drawscaledbitmap is used as function all the time, but images are mostly unscaled it is an issue


Great catch, thanks! That'll be an easy addition. :slight_smile:

1 Like