yuri91 / ili9341-rs

A WIP, no_std, generic driver for the ILI9341 (and ILI9340C) TFT LCD display
Apache License 2.0
58 stars 50 forks source link

Performance improvements without DMA #43

Closed ValouBambou closed 8 months ago

ValouBambou commented 8 months ago

Hi, I was doing a GPS like application on a Raspberry Pi Pico using embassy and embedded_graphics, and I encounter some performances issues.

First measurement

Indeed, clearing the screen took 263 ms on average and rendering the first frame of my app (rendering 20 lines) took around 340ms. These time are a bit too high for reaching the goal of 60 fps. So I planned to use DMA, but before I was wondering if there are some tweaks to improve the driver.

Considered improvements

My first idea when looking at the code was to avoid some slice to iterator conversions, e.g. in command, so based on that I try some tweaks:

With this idea, I got a speedup around 20% on the rendering of my first frame (268 ms instead of 338 ms) and just a consistent save of 1ms for clearing the screen.

yuri91 commented 8 months ago

One thing that can help a lot is to try to increase the frequency of the SPI bus. You can play with it and increase it until the device can't keep up anymore.

Looking at your numbers I think that you are indeed limited by the spi speed, because as you say you get a good speedup for the first frame, but then not so much anymore, suggesting that the bottleneck at the steady state is not the cpu.

I will add specific feedback about the PR over there.

Thanks for taking the time to experiment, report here and do a PR!

ValouBambou commented 8 months ago

I tried to increase the frequency, but now the clear method is taking 85 ms and the first frame 171 ms. While when I undo my changes the clear screen takes the same amount of time, but the first frame took 242 ms, so there is still is a big 30% difference even when the frequency is high.

Also, when I talk about the first frame it is just to simplify, the time for the next frames is also reducing.