As software engineers, we thrive to deliver software that produces correct results while being fast and using as little resources as it can. Mostly, there is a trade-off between the running time of the program and the memory it consumes, but that's not always true.
What I was trying to solve for?
The company where I work has a web-based POS system for restaurants which merchants use to punch orders and print receipts. The printing service runs as a separate application on the system. Now, it is very common for merchants to use tablets to take orders. For them, we have an Android application that runs natively on their devices.
We had observed that printing from these Android tablets, especially the older ones with slow processors, was taking a lot of time. The delay between print button being clicked and the print being triggered would reach upwards of 15 seconds on some devices! The delay was so significant that it would not justify us to market our POS system to work on such Android devices.
What caused this delay?
After profiling various components of the POS system and the printing app for Android platform, slowness was found in both of them.
- Extremely slow rendering of print receipts on the POS.
- Extremely slow conversion of the input image to ESC/POS instructions in the printing app.
Both these problems had very interesting solutions. In this post, we'll restrict ourselves to how we optimised for the printing app, and in a future post, we'll talk about how we optimised for rendering of the print receipts.
An overview of the print process
The print request is received by the printing app which contains a JSON body. The image to be printed is base64 encoded which needs to be translated to ESC/POS instructions which is understood by the thermal printers.