I reduced processing time by 50% in one of my project, I will explain how
So there’s a service that its job is to generate a new image with one image as the base layout and it will draw other components (such as text, rectangle, line, etc) on top of those image. Previously, it was using Skia to do so (Skia is an open source 2D Graphic Engine) which is reasonable option since there is a lot of drawing involved and we want it to be fast, and Skia is real fast.
It was performing well enough until it needed to output an image with a really big resolution, because there’s a case where the image will be printed in a huge banner so a big resolution is unavoidable to maintain 300 PPI (pixel per-inch) for a sharp & smooth printed image.
I was measuring which part of the pipeline took so long and found out that 96% of it was spend in image encoding, not the drawing part, and we’re talking about ~84 megapixels image, so I started to optimize the encoding options on Skia but couldn’t find significant decrease, so I try to use Libvips (an open source image processing library) because I know it has a lot of optimization trick since the whole point of Libvips is for a really fast image processing.
I migrated the drawing operation to a simple svg draw instead of rasterized image so I can feed it into Libvips and do image compositing with Libvips to achieve the same result and I can remove Skia completely, and then I measure again. The drawing part is 6-10% slower than using Skia, which is expected since that’s the whole point of Skia, to draw / paint image really fast, but remember the 96% of time in this service was spent on image encoding and Libvips really excel in that.
After the migration and fine-tuning the pipeline, the whole processing time is reduced by 50% and for smaller image it even reduced by 60%, the key takeaway here is remember to always benchmark before you do optimization, because sometimes the bottleneck is not what you think it is.

Have a nice day!