I'm benchmarking some of our code on an OPO device that's normally pretty fast and I'm seeing a lot of "weird" performance oddities. Before digging deeper into the Android native code I thought I'd ask here.
What I'm seeing is that a call for paint.setColor(argbInt)
takes roughly 5 times longer to execute than the following calls:
paint.setStyle(Paint.Style.FILL);
paint.setAntiAlias(false);
canvas.drawRect(x, y, x + w, y + h, paint);
paint.setAntiAlias(antialias);
Now draw rect happens on the GPU so I'm guessing I don't see any overhead for that. But why should I get overhead for the paint color?
And as a natural followup, how do I reduce said overhead?
I'm also seeing quite a bit of overhead for canvas.restore()
(roughly 4 times slower than the code above) but I guess that would make sense as it could be a complex operation. I just don't see why setColor
would be slow?
For the record I tested the performance on an OPO with System.nanoTime() and its pretty consistent in terms of performance (not a sudden GC fluke or something).