I am doing profiling about the execution time of each step. As far as I know, I can have multiple worker threads, and each of the worker thread can have its own recorder to do snap(). However, all the insertRecording() must be serialized in a single main thread in a serialized style. So I doubt the insertRecordings will become a bottleneck.
I draw 75 * 75 rectangles like this:
uint32_t color = 0xfffc6a03;
for(int j = 0; j < 75; j++) {
for(int i = 0; i < 75; i++) {
SkPaint paint;
//paint.setColor(color + 0xff000202 * i); ...option 1...
//paint.setColor(color); ...option 2...
SkRect rect = SkRect::MakeXYWH(i * 2, j * 2, 2, 2);
std::shared_ptr<RectDrawCmd> rectCmd = std::make_shared<RectDrawCmd>(paint, rect);
addDrawCmd(rectCmd);// later draw/snap/insertRecording
}
}
For option 2 when the color does not change, draw and snap take about 2ms, and insertRecording takes 0.06ms, which looks good to me!
However, for option 1 when the color changes for every rectangle, draw and snap still take about 2ms, but insertRecording takes about 100ms... Why is that the case? What makes the difference between option 1 and 2? How should I write the code if I want ~5000 rectangles with different colors?
Because insertRecordings need to be serialized, I don't want it to be a bottleneck.
Thank you in advance!