Up to 25× faster AI inference on the ESP32-S3.

New ESP32-S3 kernels in the DeepGate compiler run 29 open-source models a median of 2.5× faster than TFLM with esp-nn, using 2.2× less RAM.

Inference speed is critical for AI on microcontrollers. Faster models respond sooner, enabling real-time applications such as vision-based drone tracking without losing sight of a moving object or audio denoising in hearing aids without noticeable delay. Faster inference also frees up processing time for other tasks, such as reading sensors, handling wireless communication, and running application logic.

In our previous work on the DeepGate edge AI compiler, we developed kernel optimisations for Arm Cortex-M microcontrollers that ran models far faster than TensorFlow Lite for Microcontrollers (TFLM), the standard way to run models on microcontrollers. We have now developed kernels for the vector unit of Espressif’s ESP32-S3 and integrated them into the DeepGate edge AI compiler. Across 29 open-source models, the compiled models ran a median of 2.5× faster than TFLM with Espressif’s optimised esp-nn kernels, with speed-ups reaching up to 25× on individual models. The DeepGate-compiled models also used a median of 2.2× less RAM and 1.4× less flash memory. Both engines produced byte-identical outputs on every model, so the speed-up comes at no cost to model accuracy.

How models run on the ESP32-S3 today

The ESP32-S3 is a dual-core microcontroller designed with AI workloads in mind. Its two processor cores run at up to 240 MHz and feature specialised vector instructions that accelerate neural network computations by performing multiple mathematical operations simultaneously. Espressif calls these the Processor Instruction Extensions (PIE). A single PIE instruction multiplies 16 pairs of 8-bit numbers and adds the results to a running total, which is the core operation of a quantised neural network.

The standard way to run AI models on the ESP32-S3 is through esp-tflite-micro, Espressif’s port of TensorFlow Lite for Microcontrollers (TFLM). TFLM is an interpreter that executes a neural network layer by layer using pre-built kernels. For common operations such as convolution and fully connected layers, Espressif’s optimised esp-nn library takes advantage of these vector instructions. Other operations are handled by TFLM’s general-purpose kernels.

The problem

Espressif’s esp-nn library already does an excellent job of accelerating neural network calculations on the ESP32-S3. However, we identified three areas where inference performance could be further improved:

  1. Unnecessary processing during inference. TFLM interprets the model at runtime, introducing additional processing overhead during inference. For example, when a convolution layer’s weight rows are not multiples of 16 bytes, Espressif’s esp-nn library rearranges them during inference into a format suitable for the ESP32-S3’s vector hardware.
  2. General-purpose kernels aren’t optimised for every layer shape. TFLM uses kernels designed to support many different neural networks, with optimisations primarily targeting common layer shapes, such as 1×1 and 3×3 convolutions. Less common shapes, such as the long convolutions found in speech models, can therefore run significantly slower.
  3. Not all layers take advantage of hardware acceleration. Certain neural network operations, such as padding, mean operations and LSTM layers (used to process sequential data such as speech), lack optimised kernels that take advantage of the ESP32-S3’s specialised hardware, forcing them to rely on slower general-purpose code.

Our solution: optimising inference for the ESP32-S3

We extended the DeepGate edge AI compiler to generate optimised code for the ESP32-S3, eliminating unnecessary processing during inference and introducing specialised kernels that take advantage of its vector instruction capabilities. We’ve implemented four key optimisations:

  1. Eliminating unnecessary processing during inference. TFLM and esp-nn perform additional processing while the model runs, such as rearranging convolution weights into a format suitable for the ESP32-S3’s vector hardware. We adapted the DeepGate compiler to perform this preparation at compile time, eliminating the extra overhead when the model runs.
  2. Optimising kernels for different layer shapes. TFLM and esp-nn use general-purpose kernels that work well for common layer shapes but can be inefficient for less common ones, such as long convolutions in speech models. We extended the DeepGate compiler to include specialised kernels optimised for different layer shapes, selecting the appropriate kernel at compile time rather than checking layer shapes during inference.
  3. Accelerating or eliminating slow operations. Some operations in TFLM, such as LSTM and mean layers, lack kernels optimised for the ESP32-S3’s hardware, forcing them to rely on slower general-purpose code. We developed hardware-optimised kernels for these operations and eliminated unnecessary work where possible. For example, we can integrate padding directly into convolutions, avoiding the need to create a separate padded copy of the input.
  4. Reducing unnecessary memory access. Model weights are stored in flash memory and accessed through the ESP32-S3’s cache. When weights don’t fit in the cache, repeatedly fetching them from flash slows down inference. We optimised the order of calculations to minimise these accesses. For example, we developed an LSTM kernel that computes the input part of all time steps together, allowing input weights to be read from flash memory once rather than separately for each time step.

Importantly, these optimisations don’t change the model or its predictions. Our kernels reproduce TFLM’s integer arithmetic exactly, producing byte-identical outputs, while reducing unnecessary computation and memory access.

Further implementation details are provided in the Methods and technical details section below.

Results

We ran 29 open-source models spanning image classification, object detection, keyword spotting, speech recognition, audio denoising, anomaly detection and more on ESP32-S3 boards, once with TFLM and esp-nn and once compiled by the DeepGate compiler, and compared their latency per inference.

Latency

The DeepGate compiler was faster on every model: a median of 2.5× faster, with the fastest speed-up reaching 25×.

The DeepGate compiler was faster than TFLM on all 29 models
Median speed-up 2.5×, ranging from 1.04× to 25×
LatencySpeed-up
LSTM micro_speech25.19×TFLM with esp-nn 327.94 ms, DeepGate compiler 13.02 ms
Tiny Wav2letter11.37×TFLM with esp-nn 6.80 s, DeepGate compiler 598.52 ms
DS-CNN-L4.73×TFLM with esp-nn 273.68 ms, DeepGate compiler 57.84 ms
DS-CNN-M4.41×TFLM with esp-nn 100.06 ms, DeepGate compiler 22.7 ms
MicroNet-AD-L4.39×TFLM with esp-nn 634.87 ms, DeepGate compiler 144.55 ms
TFLM micro_speech3.78×TFLM with esp-nn 2.72 ms, DeepGate compiler 0.72 ms
MicroNet VWW-43.72×TFLM with esp-nn 282.23 ms, DeepGate compiler 75.95 ms
MicroNet-KWS-L3.55×TFLM with esp-nn 467.32 ms, DeepGate compiler 131.67 ms
Magic wand3.55×TFLM with esp-nn 4.65 ms, DeepGate compiler 1.31 ms
MiniResNetV23.29×TFLM with esp-nn 99.22 ms, DeepGate compiler 30.18 ms
MCUNet-in22.87×TFLM with esp-nn 1.01 s, DeepGate compiler 350.36 ms
MCUNet person detector2.63×TFLM with esp-nn 277.16 ms, DeepGate compiler 105.4 ms
MCUNet VWW2.60×TFLM with esp-nn 155.24 ms, DeepGate compiler 59.75 ms
BlazeFace2.57×TFLM with esp-nn 495.95 ms, DeepGate compiler 192.63 ms
MLPerf visual wake words2.48×TFLM with esp-nn 56.23 ms, DeepGate compiler 22.64 ms
MLPerf image classification, large2.46×TFLM with esp-nn 221.51 ms, DeepGate compiler 89.94 ms
YAMNet-2562.46×TFLM with esp-nn 132.4 ms, DeepGate compiler 53.88 ms
MobileNetV1-0.252.31×TFLM with esp-nn 385.25 ms, DeepGate compiler 166.57 ms
MLPerf streaming wake word2.12×TFLM with esp-nn 3.61 ms, DeepGate compiler 1.7 ms
MLPerf keyword spotting2.03×TFLM with esp-nn 16.47 ms, DeepGate compiler 8.11 ms
MobileNetV2-0.352.03×TFLM with esp-nn 308.57 ms, DeepGate compiler 152.36 ms
EfficientNet-Lite01.98×TFLM with esp-nn 2.74 s, DeepGate compiler 1.38 s
MLPerf image classification1.93×TFLM with esp-nn 43.78 ms, DeepGate compiler 22.69 ms
DTLN1.91×TFLM with esp-nn 22.14 ms, DeepGate compiler 11.59 ms
MobileNetV2-1.01.80×TFLM with esp-nn 1.83 s, DeepGate compiler 1.02 s
TFLM person detection1.64×TFLM with esp-nn 48.79 ms, DeepGate compiler 29.75 ms
RNNoise1.41×TFLM with esp-nn 4.32 ms, DeepGate compiler 3.06 ms
WISDM activity recognition1.37×TFLM with esp-nn 35.45 ms, DeepGate compiler 25.94 ms
MLPerf anomaly detection1.04×TFLM with esp-nn 8.79 ms, DeepGate compiler 8.42 ms
Median latency per inference, log scaleDeepGate ESP32-S3 benchmark · 29 models · median of 10 inferences on an ESP32-S3-DevKitC-1 at 240 MHz
Each row is one model, sorted by speed-up. The grey bar spans the gap between the two latencies on a log scale, so its length shows the ratio, and the right column shows the speed-up.

The two largest gains came from the DeepGate compiler accelerating layers that esp-nn does not optimise well. The LSTM micro_speech model ran 25 times faster, because TFLM runs its LSTM layer on portable C: 327 ms against our 13 ms. Tiny Wav2letter ran 11 times faster: its convolutions took 6.7 s with TFLM and 0.59 s with ours, and seven of its nine convolutions have 1×7 to 1×48 windows that miss esp-nn’s fast paths.

Convolutions accounted for the largest time saving on 21 of the 29 models. The DeepGate compiler ran standard convolution layers a median of 2.3× faster than TFLM, and depthwise convolution layers 2.2× faster.

Eight of the 29 models required padding, which took TFLM between 4 ms and 279 ms per inference. The DeepGate compiler eliminated padding entirely in five models and accelerated it by at least 80% in the remaining three.

The smallest gain was on the MLPerf anomaly detection model (1.04 times), which consists only of fully connected layers. esp-nn’s fully connected kernel is already close to ours: on the 11 models with such layers, they ran a median of 1.05 times faster.

Memory

The DeepGate-compiled models also used less memory than TFLM on 28 of the 29 models, with a median reduction of 2.2× in RAM and 1.4× in flash usage.

The compiled models also needed less RAM and flash
Median of 2.2× less RAM and 1.4× less flash than TFLM
RAM (arena)Smaller by
Tiny Wav2letter11.6×TFLM with esp-nn 2.45 MiB, DeepGate compiler 216.8 KiB
RNNoise8.1×TFLM with esp-nn 7.9 KiB, DeepGate compiler 1.0 KiB
Magic wand4.3×TFLM with esp-nn 32.3 KiB, DeepGate compiler 7.5 KiB
MicroNet VWW-43.2×TFLM with esp-nn 181.2 KiB, DeepGate compiler 56.0 KiB
DS-CNN-L3.2×TFLM with esp-nn 273.9 KiB, DeepGate compiler 84.9 KiB
DS-CNN-M3.2×TFLM with esp-nn 169.5 KiB, DeepGate compiler 52.9 KiB
MLPerf anomaly detection3.1×TFLM with esp-nn 2.3 KiB, DeepGate compiler 0.8 KiB
MicroNet-KWS-L3.1×TFLM with esp-nn 509.7 KiB, DeepGate compiler 165.8 KiB
MicroNet-AD-L2.9×TFLM with esp-nn 1008.2 KiB, DeepGate compiler 345.0 KiB
MLPerf streaming wake word2.8×TFLM with esp-nn 18.5 KiB, DeepGate compiler 6.5 KiB
MCUNet VWW2.3×TFLM with esp-nn 219.5 KiB, DeepGate compiler 93.8 KiB
DTLN2.3×TFLM with esp-nn 4.5 KiB, DeepGate compiler 2.0 KiB
MLPerf keyword spotting2.2×TFLM with esp-nn 34.7 KiB, DeepGate compiler 15.6 KiB
TFLM person detection2.2×TFLM with esp-nn 118.2 KiB, DeepGate compiler 54.0 KiB
MLPerf visual wake words2.2×TFLM with esp-nn 118.1 KiB, DeepGate compiler 54.0 KiB
MobileNetV1-0.252.1×TFLM with esp-nn 528.6 KiB, DeepGate compiler 257.3 KiB
MobileNetV2-0.351.9×TFLM with esp-nn 455.7 KiB, DeepGate compiler 235.0 KiB
BlazeFace1.8×TFLM with esp-nn 588.8 KiB, DeepGate compiler 336.0 KiB
MiniResNetV21.6×TFLM with esp-nn 113.6 KiB, DeepGate compiler 70.4 KiB
MLPerf image class., large1.6×TFLM with esp-nn 202.0 KiB, DeepGate compiler 130.0 KiB
MLPerf image classification1.5×TFLM with esp-nn 80.5 KiB, DeepGate compiler 52.5 KiB
TFLM micro_speech1.5×TFLM with esp-nn 11.8 KiB, DeepGate compiler 8.0 KiB
MCUNet-in21.4×TFLM with esp-nn 528.1 KiB, DeepGate compiler 373.4 KiB
MCUNet person detector1.2×TFLM with esp-nn 371.3 KiB, DeepGate compiler 300.0 KiB
YAMNet-2561.2×TFLM with esp-nn 173.9 KiB, DeepGate compiler 144.0 KiB
EfficientNet-Lite01.1×TFLM with esp-nn 1.64 MiB, DeepGate compiler 1.44 MiB
MobileNetV2-1.01.1×TFLM with esp-nn 1.62 MiB, DeepGate compiler 1.44 MiB
WISDM activity recognition1.1×TFLM with esp-nn 29.9 KiB, DeepGate compiler 27.8 KiB
LSTM micro_speech2.3× largerTFLM with esp-nn 18.6 KiB, DeepGate compiler 43.2 KiB
FlashSmaller by
Tiny Wav2letter1.1× largerTFLM with esp-nn 3.86 MiB, DeepGate compiler 4.09 MiB
RNNoise2.2×TFLM with esp-nn 215.3 KiB, DeepGate compiler 98.4 KiB
Magic wand3.3×TFLM with esp-nn 96.4 KiB, DeepGate compiler 28.9 KiB
MicroNet VWW-41.9×TFLM with esp-nn 580.5 KiB, DeepGate compiler 311.2 KiB
DS-CNN-L1.2×TFLM with esp-nn 583.8 KiB, DeepGate compiler 472.8 KiB
DS-CNN-M1.7×TFLM with esp-nn 273.7 KiB, DeepGate compiler 165.8 KiB
MLPerf anomaly detection1.1×TFLM with esp-nn 295.6 KiB, DeepGate compiler 266.7 KiB
MicroNet-KWS-L1.2×TFLM with esp-nn 716.2 KiB, DeepGate compiler 574.6 KiB
MicroNet-AD-L1.2×TFLM with esp-nn 504.4 KiB, DeepGate compiler 410.7 KiB
MLPerf streaming wake word2.7×TFLM with esp-nn 158.9 KiB, DeepGate compiler 59.4 KiB
MCUNet VWW1.4×TFLM with esp-nn 722.7 KiB, DeepGate compiler 507.5 KiB
DTLN1.1×TFLM with esp-nn 405.2 KiB, DeepGate compiler 364.6 KiB
MLPerf keyword spotting4.0×TFLM with esp-nn 144.4 KiB, DeepGate compiler 36.3 KiB
TFLM person detection1.5×TFLM with esp-nn 378.7 KiB, DeepGate compiler 246.5 KiB
MLPerf visual wake words4.0×TFLM with esp-nn 417.2 KiB, DeepGate compiler 105.2 KiB
MobileNetV1-0.251.4×TFLM with esp-nn 696.3 KiB, DeepGate compiler 511.8 KiB
MobileNetV2-0.351.1×TFLM with esp-nn 1.94 MiB, DeepGate compiler 1.69 MiB
BlazeFace1.9×TFLM with esp-nn 289.9 KiB, DeepGate compiler 152.1 KiB
MiniResNetV21.9×TFLM with esp-nn 257.4 KiB, DeepGate compiler 135.7 KiB
MLPerf image class., large1.3×TFLM with esp-nn 585.9 KiB, DeepGate compiler 451.4 KiB
MLPerf image classification2.1×TFLM with esp-nn 182.1 KiB, DeepGate compiler 86.8 KiB
TFLM micro_speech4.3×TFLM with esp-nn 81.9 KiB, DeepGate compiler 19.0 KiB
MCUNet-in21.3×TFLM with esp-nn 1.06 MiB, DeepGate compiler 838.6 KiB
MCUNet person detector1.7×TFLM with esp-nn 397.7 KiB, DeepGate compiler 228.5 KiB
YAMNet-2561.7×TFLM with esp-nn 278.3 KiB, DeepGate compiler 159.8 KiB
EfficientNet-Lite01.1×TFLM with esp-nn 5.28 MiB, DeepGate compiler 4.71 MiB
MobileNetV2-1.01.1×TFLM with esp-nn 3.94 MiB, DeepGate compiler 3.57 MiB
WISDM activity recognition1.1×TFLM with esp-nn 797.5 KiB, DeepGate compiler 728.6 KiB
LSTM micro_speech1.3×TFLM with esp-nn 172.5 KiB, DeepGate compiler 129.0 KiB
KiB, log scaleDeepGate ESP32-S3 benchmark · 29 models · arena and flash sizes reported by each firmware build
Each row is one model, sorted by the RAM saving. RAM is the arena, the block of memory that holds a model’s activations and runtime data. Flash covers each engine’s code and the model’s weights. Both scales are logarithmic.

The two exceptions are trade-offs for speed. The LSTM kernel keeps the input part of all 49 time steps in a 31 KiB buffer, so LSTM micro_speech needs 43 KiB of RAM against TFLM’s 19 KiB. Tiny Wav2letter’s weights are padded for aligned vector loads, which makes its flash 6% larger than TFLM’s.

Impact

By reducing inference latency and memory requirements, the DeepGate compiler enables developers to build more capable AI applications on the ESP32-S3 without retraining or modifying their existing models.

  • Faster, more capable applications. Faster inference allows devices to respond sooner, process data more frequently, or run larger, more accurate models within the same time budget. For example, smart cameras can track moving objects more frequently and respond faster to changes in their environment.
  • More room for AI and other tasks. Lower RAM and flash requirements leave more memory available for larger models, application code, and other functionality, potentially allowing developers to use lower-cost hardware.

Methods and technical details

The kernels in more detail

  • Dot products. Convolution, fully connected and LSTM layers use the EE.VMULAS.S8.ACCX.LD.IP instruction. It multiplies 16 pairs of 8-bit values into a 40-bit accumulator and loads the next 16 bytes in the same instruction. With the core’s zero-overhead loop, that is 16 multiply-adds every two instructions, the same inner loop esp-nn uses.
  • Depthwise convolution. A depthwise layer has no sum over input channels, so the kernels run the vector unit across 16 channels at once instead. Each lane holds a 20-bit total, which can take 31 full-range products without overflowing, so windows of up to 31 taps run in one pass.
  • Large convolutions. When a layer’s weights exceed the 64 KB data cache, the kernels split the output channels into 24 KB panels of weights and keep each panel in the cache while it is used. One-dimensional convolutions skip gathering input patches altogether, because each output reads one contiguous run of the input.
  • LSTM. TFLM computes the input part of each gate one time step at a time, so the input weights are read from flash once per step. Our kernel computes that part for all time steps first, reading each weight row once.
  • Softmax. The reference softmax evaluates an exponential twice per element, which costs about 290 cycles per element on the ESP32-S3. Because 8-bit inputs allow only 256 possible differences, the compiler folds every exponential into a 256-entry table.

Models

We used the same 29 open-source TensorFlow Lite models, all quantised to 8-bit integers. They come from the MLPerf Tiny benchmark, the TensorFlow Lite for Microcontrollers examples, the Arm ML-Zoo, the MCUNet project and the Apache-2.0 part of the ST model zoo. All are available under the Apache-2.0 or MIT licence, and all 29 compile for the ESP32-S3.

Use caseModels
MLPerf TinyVisual wake words, image classification (standard and large), keyword spotting, anomaly detection, streaming wake word
Person detectionTFLM person detection, MicroNet VWW-4, MCUNet VWW
Image classificationMCUNet-in2, MobileNetV1-0.25, MobileNetV2-0.35, MobileNetV2-1.0, EfficientNet-Lite0
Object detectionBlazeFace, MCUNet person detector
Keyword spottingTFLM micro_speech, DS-CNN-M, DS-CNN-L, MicroNet-KWS-L, LSTM micro_speech
Gesture and activityMagic wand, WISDM activity recognition
Anomaly detectionMicroNet-AD-L
Audio eventsYAMNet-256, MiniResNetV2
Noise suppressionRNNoise, DTLN
Speech recognitionTiny Wav2letter

Hardware and software

Both engines ran on ESP32-S3-DevKitC-1 boards (N16R8 module), built from the same chip configuration and test harness. The CPU ran at 240 MHz with a 32 KB instruction cache and a 64 KB data cache, quad-I/O flash at 80 MHz and octal PSRAM at 80 MHz.

TFLMDeepGate
Softwareesp-tflite-micro 1.4.1 with esp-nn 1.4.1DeepGate compiler 0.4.2
BuildESP-IDF v5.5.5, GCC 14.2.0; esp-tflite-micro at -O3, as Espressif ships itESP-IDF v5.5.5, GCC 14.2.0; generated C at -O2
Kernels linkedOnly the model’s layer typesOnly the kernels the model’s layers use

Weights stayed in flash for both engines and were read through the cache. Activations were placed in internal RAM, or in PSRAM for the 11 models whose activations do not fit there, the same for both engines. Both ran on one core: esp-nn 1.4.1 can split some layers across the second core when an application opts in, which the benchmark does not.

Measurement

Each latency is the median of 10 inferences after 3 warm-up runs, measured using the CPU cycle counter. Per-layer timings were obtained from separate profiling builds.

RAM is the arena reported by each engine: TFLM’s arena_used_bytes() and the DeepGate compiler’s arena plus any recurrent layer state. Flash is the size of the model and its linked libraries.

Checking the results

For each model, both engines ran the same five inputs on the board, and their outputs were byte-identical on all 29 models.

We also compared each engine’s outputs with LiteRT’s reference kernels, run on a computer on the same inputs. Both engines matched the reference exactly on 25 models. On the other four, both differed from it by the same few quantisation levels (2 to 10), so the difference lies in TFLM’s arithmetic, which we reproduce.

Sources