Optimizing I2C/SPI OLED display refresh rate and reducing frame buffer latency on ESP32 / Arduino

I am working on a custom controller hardware interface that streams real-time telemetry and simple state graphics onto a small 0.96" SSD1306 OLED display using an ESP32 micro-controller board.

While the basic Adafruit_SSD1306 / U8g2 setup works fine for rendering static text, I am hitting a performance bottleneck when attempting to render continuous high-framerate sprite animations and fast state indicators. The display refresh rate stutters, and updating the full display frame buffer blocks my main loop() processing time.

A few technical questions for the display and firmware experts here:

  1. Is switching from I2C (400kHz Fast Mode) to Hardware SPI the most effective way to eliminate screen tearing during frequent bitmap redrawing?

  2. Has anyone benchmarks comparing dynamic screen redraws (only updating dirty bounding boxes/pixels) versus pushing full frame buffer updates (display.display()) on U8g2 library setups?

  3. What are the best practices for handling non-blocking timer loops (millis()) so that display rendering doesn't freeze serial data parsing or analog pin inputs?

Any code snippets, library recommendations, or hardware optimization tips would be greatly appreciated!

I think screen tearing is caused by updating the screen slowly so that parts of 2 frames are briefly visible. Is that what you mean?

Hardware SPI is many times faster than I2C.
A basic Uno R3 is already 10-20x faster.
I don't know what the clock on an ESP32 defaults to. Could be 40MHz (100x 400kHz).
Could also depend on which version of the ESP32 you're using.
SPI is definitely worth a try.

The fastest I ever got an OLED display to uplate was using hardware SPI combined with using a hardware DMA channel, on a Arduino Zero/M0 clone.

I think part of the screen tearing is caused the OLED controller refreshing the display while your code is in the process of updating the display's memory buffer. I doubt there is anything you can do about that.

If you only need to update a small portion of the display, it is possible to mix U8g2 and U8x8 code, which allows you to use all the U8g2 functions to generate graphics, text, etc, in the memory buffer, then use U8x8 code to only send a specific portion of that buffer to the display.

Generally, SPI will be faster. Without knowing the actual bus speeds being used, you can calculate the bit rates for both SPI and I²C; that will quickly show which one has the higher potential transfer rate.

Keep in mind that both bus speeds are programmable, so the actual rate depends on how they are configured. You also need to check those settings against the display controller's maximum SPI/I²C clock rate and its maximum practical update rate.