I compare some of our code on an OPO device, which is usually pretty fast, and I see a lot of “weird” characteristics. Before delving into Android's native code, I thought I'd ask here.
I see that the call to paint.setColor(argbInt) takes about 5 times longer 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 a rectangle looms on the GPU, so I guess I don’t see the overhead for this. But why should I get the overhead for the color of the paint?
And as a natural continuation, how to reduce the indicated overhead?
I also see quite a bit of overhead for canvas.restore() (about 4 times slower than the code above), but I assume this will make sense, as it can be a complicated operation. I just don't understand why setColor will be slow?
For the record, I tested the performance on OPO with System.nanoTime () and its pretty consistent in terms of performance (rather than the sudden GC fluke or something else).
source share