Before moving a TinyML project from ESP32-S3 to ESP32-S31, find the number that is actually causing trouble. Is it the time spent inside the model, the wait for the next camera frame, or the largest block of internal RAM you can still allocate after Wi-Fi starts? These three problems can produce the same symptom on the bench. The app misses its deadline and the chip gets blamed.
Start with the exact same model and saved inputs on both boards. Once the outputs agree within your test limits, time inference on its own. Then put the camera, microphone, display or network tasks back in. This esp32.co.uk/ guide gives a way to do that and a memory sheet to catch what the tensor arena figures leave out. Hardware results are pending.

The hardware difference that matters
The S31 has dual high-performance RISC-V cores, up to 320 MHz, and 512 KB of high-performance SRAM. Its preliminary v0.6 datasheet lists 8 MB, 16 MB and 32 MB in-package PSRAM variants. It describes 128-bit data access with SIMD instructions on one of the high-performance cores. When planning a test, find out which task is executing the model and what the port does to select a suitable core. Two application cores give you scheduling options. They do not tell you that two cores can run the same vector kernel. ESP32-S31 datasheet
The S3 has dual Xtensa LX7 cores, up to 240 MHz, and 512 KB of on-chip SRAM. It has its own vector instruction extensions. PSRAM depends on the variant, and a board with more flash does not necessarily have more PSRAM. Look at the exact marking and the boot log. If you are comparing an S3 module with 8 MB of PSRAM to an S31 board with 16 MB, write down both before drawing any conclusion about what fits. ESP32-S3 datasheet, S3 flash and PSRAM variants
| Feature | ESP32-S31 | ESP32-S3 |
|---|---|---|
| Application processor | Dual-core RISC-V, up to 320 MHz | Dual-core Xtensa LX7, up to 240 MHz |
| Main on-chip SRAM figure | 512 KB HP SRAM | 512 KB on-chip SRAM |
| PSRAM | 8, 16 or 32 MB in the cited preliminary part list | Variant and module dependent |
| ESP-NN route | RISC-V PIE/QACC family | Xtensa SIMD family |
Clock speed is useful for reproducing a result. A 320-to-240 MHz ratio cannot predict the change in latency. The cores use different instruction sets, libraries and memory paths. One convolution may hit a good vector path while the next operation takes a fallback route. And the model reads weights as it works. If those reads keep stalling, the higher clock can spend more cycles waiting.
The S31 includes dedicated peripherals for work such as JPEG and pixel processing. If a camera pipeline can use those blocks through its driver, measure the change at the pipeline level. A hardware image transform can save time before the first tensor reaches the model. Record that gain as preprocessing. The general board and chip comparisons cover the rest of the peripheral differences. S31 development boards, S31 and S3 chip comparison
Pin the runtime and check the kernel path
TensorFlow Lite Micro, or TFLM, runs a .tflite graph with registrations for the operators compiled into the application. Espressif integrates ESP-NN through its TFLM component. ESP-NN v1.3.0 added S31 support, using the RISC-V PIE/QACC kernel family shared with P4. S3 has a separate SIMD implementation. Support for a target in the library tells you that the paths exist. The build and individual operator parameters determine what gets used. Espressif TFLM component, ESP-NN releases
For a fresh bench comparison, ESP-IDF v6.1.1, esp-tflite-micro 1.4.3 and ESP-NN 1.5.0 are a starting version set to try with compatible boards and tooling. Save the versions that actually resolve. The TFLM manifest allows ESP-NN releases from 1.4.2 onward, so a fresh dependency resolution can change which implementation you are measuring. Keep dependencies.lock, the effective sdkconfig, compiler flags and the firmware commit or binary hash for each target. TFLM dependency manifest, ESP-NN v1.5.0 release notes
Where your selected component has the setting, make two builds per board. Set CONFIG_ESP_TFLITE_MICRO_USE_ESP_NN on for the optimised build and off for the reference build through menuconfig. Compare the same model, allocation policy and input set. This gives you a baseline for checking both correctness and benefit. Start with one inference task and leave any optional multi-core kernel worker disabled. For a later run with workers, record the eligible operators, any affinity constraints, task stacks and other application load. ESP TFLite-Micro Kconfig
Versions matter even if the graph stays the same. The 1.5.0 release notes describe a change to claiming the dual-core worker and name TFLM 1.4.2 and 1.4.3 as examples of different integration behaviour. If someone sends you a result with just “ESP-NN enabled” in the notes, ask for the pair of component versions. And record where runtime data lives. Alignment and tensor geometry can affect whether a particular fast path is eligible. ESP-NN v1.5.0 release notes
Use one model for the first comparison
Pick a small INT8 model close to the real task. For a camera, a fixed-size grayscale classifier gives you fewer preprocessing variables than a complete detector. For audio, start with a model that consumes saved feature tensors. You need an input file that both boards can load byte for byte. Decide how you will compare outputs and which errors matter before collecting timings.
Get that one model running in the chosen ESP TFLite-Micro example or your existing port. Inspect the installed example’s operator resolver and replace or add registrations to match the graph. A model can fit in flash and still fail setup because one operator or its version is unsupported. Keep the model and resolver the same on both targets. Use separate build directories or project copies and set each target from its own directory. No need to carry an old S3 build cache into the S31 project.
Record the model SHA-256, input tensor dimensions and layout, data type, scale and zero point. Record the operator names and versions. Use the same tensor bytes in the same order, including the same initial state for a stateful model. Save the expected output tensors or the reference results from the chosen software path. A quick known-answer run can catch a bad port before you spend an afternoon measuring it.
For a stronger comparison, include at least two models or two input sizes and state why. A convolution-heavy image classifier spends time in different places from a small dense sensor model, and a network that fits comfortably in internal RAM can behave differently when its arena moves to PSRAM. Keep each model as its own row. An average across unrelated models will be difficult to apply to the one you care about.
Use the ESP-IDF shell belonging to the SDK you chose. Make two fresh project copies. Set idf.py set-target esp32s3 in the S3 copy and idf.py set-target esp32s31 in the S31 copy. If your starting example requires a board-specific camera or display driver, use its supported inference-only configuration or your own capture-free test project. The command selects a chip and the example still has to support that chip. ESP-IDF command reference
# Run in each copy after setting the target.
idf.py menuconfig
idf.py build
Save the boot transcript from the first correct run. Check that it names the intended target and the expected PSRAM, and that the application prints the same model identifier on both. Keep the build maps. If a vendor demo reports a very different number, check its input shape, enabled tasks and actual model file first. Names such as person detection can describe models with very different graphs.

Check the input and output before changing performance settings
Quantised inputs are easy to get almost right. For an INT8 tensor, dequantisation is real = (q - zero_point) × scale. To encode an input, apply the same preprocessing as the reference, divide by the positive scale, round with the reference convention, add the zero point and clamp to −128 through 127. If normalised input is 0.5, the scale is 1/128 and the zero point is −3, the integer is 61. Subtracting 128 from a camera byte works only where the model’s preprocessing and quantisation make that transformation correct. LiteRT INT8 quantisation specification
Check channel order, stride and tensor dimensions as well. A camera driver may give you RGB565 with padding, while the model expects contiguous RGB or grayscale. Conversion may need to swap bytes, crop or resize first. Capture the processed tensor at the final copy into the model. If the reference and target input hashes differ, compare the first differing row. It is often much easier than staring at the final prediction.
Use a small fixture set that includes ordinary data and awkward cases. For a binary classifier, keep clearly positive and negative samples as well as examples near the threshold. For a detector, compare outputs before the filtering stage as well as the final boxes. Testing one favourite example can miss a channel swap, a rounding difference or a shape the optimised kernel handles differently.
Record what agreement means. Exact integers may be appropriate for a matched reference check. A model migration with target-specific exports can need a defined tolerance or a task metric. A top label alone can hide changes in scores that affect a decision threshold. If a test fails, keep that configuration out of the comparison until you understand the mismatch. It can be fast and still be producing the wrong output.
Work out where the RAM went
Model bytes in flash are one part. The tensor arena holds the model’s working memory, with allocations for activations, scratch and runtime data. Your application also needs task stacks, drivers, input queues, sensor buffers, network memory and perhaps a display framebuffer. Some of these sit outside the arena. Keep a list of what is allocated, which pool it uses and when that allocation happens. TFLM memory management
| Worked example | Calculation | Tightly packed size |
|---|---|---|
| 96 × 96 grayscale INT8 input | 96 × 96 × 1 byte | 9,216 bytes (9 KiB) |
| 96 × 96 RGB INT8 input | 96 × 96 × 3 channels × 1 byte | 27,648 bytes (27 KiB) |
| 320 × 240 RGB565 camera frame | 320 × 240 × 2 bytes | 153,600 bytes (150 KiB) |
| Two such camera frames | 2 × 153,600 bytes | 307,200 bytes (300 KiB) |
| 1 second mono PCM at 16 kHz, signed 16-bit | 16,000 samples × 2 bytes | 32,000 bytes (31.25 KiB) |
These are payload sizes. A camera driver may have padded lines, descriptor memory and more frames in flight. For audio, feature extraction and overlap between windows can add buffers. If the 9 KiB input tensor lives in the arena, it is already part of arena usage. Count a second 9 KiB only if you keep a separate copy. When the capture and inference tasks run at the same time, their high points matter more than the number on the sticker.
A full model file does not necessarily have a full RAM copy. A read-only embedded flatbuffer can usually be accessed in place through the flash mapping. Some ports copy selected weights or use caches, so check your actual build. Inspect the linker map for model bytes, static buffers and firmware sections. If you load from storage into an allocated buffer, include that allocation and keep the backing bytes alive as long as the interpreter needs them.

Measure the arena and the heap at the same stages
Call AllocateTensors() explicitly and check the result before timing inference. Save the reserved arena size and report arena_used_bytes() after allocation where the chosen interpreter provides it. That reports usage from the allocator in that build. It does not cover the camera, all driver allocations, task stacks or every temporary allocation outside the arena. Keep the arena’s alignment and actual placement with the results. Espressif TFLM interpreter header
Measure internal byte-addressable heap and PSRAM separately. Record total free bytes and largest free block before allocating the arena, after model setup, after starting peripherals and after the longest workload run. An internal DMA-capable view may be needed as well, depending on the peripheral. It overlaps the internal heap figures. A board can report plenty of free RAM across all regions and still fail a request for a single large block of a particular capability. ESP-IDF S31 heap API, ESP-IDF S3 heap API
For the first tests, pick explicit memory placements instead of relying on default malloc() behaviour. When the port and operator allow it, try an internal arena and a PSRAM arena as separate configurations. Keep the buffer source and address alignment documented. Check the boot log for actual PSRAM size, and check for allocation failure immediately. An automatic fallback can produce a perfectly good inference from an unexpected memory bank, which ruins the A/B comparison. S31 external RAM guide
If you need to see the division between persistent allocations and working memory, use TFLM’s recording allocator in a diagnostic build. It has overhead of its own. Use the normal interpreter for the final run. When finding the smallest stable arena, reinitialise cleanly for each candidate size with the same alignment and hardware load. Run the complete fixture set. A successful allocation with a few bytes left at boot is a reason to examine the margin under the actual application.
Find which allocation really sets the limit
Write down the order the real firmware allocates things. In one test, allocate the arena before starting the network and camera. In another, start the services in their production order. Read the largest suitable block immediately before the arena request in both cases. A difference here can explain why the same model works in a benchmark project but fails after joining Wi-Fi. If you change initialisation order as a fix, verify that the services still have the memory they need to start and reconnect.
For example, the first two camera buffers in the table account for 300 KiB before any driver overhead. A hypothetical 128 KiB arena plus those buffers accounts for 428 KiB of storage if all three allocations are separate. Putting both camera buffers and the arena in internal RAM would leave very little of the nominal 512 KB for the rest of the system, and the available contiguous heap is smaller than the datasheet number. Try moving a buffer only if the driver and kernel can use that bank. Leave the placement in your results row.
An allocation sweep can help if you know the graph is correct. Pick a working aligned arena, lower the reserved size in steps and stop at the first failing configuration, with a fresh interpreter each time. Log the failure reason alongside the size. If it fails during setup, find out whether the arena allocation itself returned null or whether AllocateTensors() rejected the space available inside it. If the model still passes, run the capture and radio load for long enough to see if anything outside the arena starts failing.
One more check. Watch whether free heap or the largest block keeps falling during a repeatable scene. A snapshot after startup won’t catch a queue that grows with every frame. Keep a series of samples at the same point in the application loop. You can then tell if reserve space is genuinely too small, or if buffers are staying live when they should have been returned.
Time the model with one small wrapper
The following C++ fragment goes into an existing ESP-IDF TFLM project. It accepts one saved INT8 tensor and an interpreter with tensors already allocated. The copy happens before the clock starts. Log the resulting status and duration after the timed section. This helper is for a single input model with a contiguous tensor.
#include <cstddef>
#include <cstdint>
#include <cstring>
#include "esp_timer.h"
#include "tensorflow/lite/micro/micro_interpreter.h"
TfLiteStatus measure_invoke(tflite::MicroInterpreter& interpreter,
const std::int8_t* sample,
std::size_t sample_bytes,
std::int64_t& elapsed_us)
{
elapsed_us = -1;
if (interpreter.inputs_size() != 1 || sample == nullptr) {
return kTfLiteError;
}
TfLiteTensor* input = interpreter.input(0);
if (input == nullptr || input->type != kTfLiteInt8 ||
input->data.int8 == nullptr || input->bytes != sample_bytes ||
sample_bytes == 0) {
return kTfLiteError;
}
std::memcpy(input->data.int8, sample, sample_bytes);
const std::int64_t start_us = esp_timer_get_time();
const TfLiteStatus status = interpreter.Invoke();
elapsed_us = esp_timer_get_time() - start_us;
return status;
}
The caller supplies a separate, non-overlapping fixture buffer and checks its shape and quantisation metadata against the model. Use the ESP-IDF esp_timer dependency as needed in your component. This gives wall time in microseconds, including scheduler delays that happen inside the measurement window. It leaves out capture, tensor copy, output reading and logging. A validation error leaves elapsed time at −1. A failed call to Invoke() still has an elapsed time. Keep it with the failure, outside your successful latency statistics. ESP Timer API
For a stateful graph, reset or replay its state in a defined way between sequences. Do that outside this timing window, unless state reset is part of the job you are measuring. Keep instrumented profiling out of the final timing run if it changes the result. A GPIO marker and a logic analyserPriceAliExpress price can cross-check a timing boundary, provided the marker calls are placed consistently.

Run cold, warm and under ordinary load
Measure cold start separately. Time model setup and the first successful inference, then record when the first usable result reaches the application. This is the number that affects a device waking to handle one job. A warm loop with the model resident gives a different result and is useful for a device that runs all day.
For the warm run, set an explicit warm-up count and trial count. For example, discard five planned warm-up invocations, collect 100 measured invocations per run and repeat the run three times. For a large or slow model, choose counts that fit your test time and give you enough completed samples to read a percentile. Keep the same input sequence and counts on both boards. Store microseconds and convert the final summaries to milliseconds. Set a restart and recovery policy for failures.
Report median, p95 and maximum for successful Invoke() calls along with successful attempts over total attempts. If you use nearest rank, sort the durations and choose the item at rank ceiling of 0.95 times the number of successful samples, counted from one. A run with 100 successes uses rank 95. A run with only 12 successes ends up with the maximum for p95. Say how many successful calls went into it.
Bring production work back in gradually. Run with the camera or audio capture enabled, then with both capture and the usual radio traffic, then with any display updates. Use a realistic rhythm and keep a counter for missed jobs. Capturing new data at a fixed rate can fill a queue if inference is slow. Measure queue age and dropped frames, because a fast Invoke() on an old frame can still make the product feel slow.
Attach a result record to every scheduled job you can observe, including failed input reads and late results. Distinguish a dropped input, a model error and a prediction that arrived too late to be used. If only 80 of 100 jobs completed, the successful p95 can look fine while the application is losing one in five inputs. Keep counts for all outcomes and preserve the measurements from the failed run so the next configuration has a fair baseline.
If the application changes the CPU clock or turns on networking partway through a session, put a marker in the log for that change. For the isolated run use a documented, fixed supported clock setting where practical. Then run the production policy with ordinary background activity. Wall time is the right number to use for an application deadline. A cycle count for an individual operator is useful for finding where compute time went, and it cannot see a late camera frame.
Camera and audio have different deadlines
For a camera pipeline, record the time of the captured frame if the driver makes that available. Identify when the application takes ownership, when crop and resize finish, and when the result is ready. The time spent waiting for a free camera buffer and the age of the selected frame can be large at low frame rates. Try a single-frame policy before adding deeper queues. More buffers can improve overlap and also let you work through old frames.
For audio, measure the hop interval between model inputs as well as the full audio window. If a one-second window advances every 100 ms, the app normally has a new job every 100 ms once it is running. Include feature extraction and scheduling in that budget. If work arrives faster than it completes, watch for overlapping inference calls on the same interpreter or an unbounded queue. A stable design should give each job a clear owner and define what gets dropped when load spikes.
For both paths, note whether a buffer has to be acceptable to DMA, which copy crosses into PSRAM and which memory bus the camera or display is exercising while inference runs. Only use a buffer placement the particular driver documents. If running with I/O causes longer tail latency, repeat with one peripheral disabled or at a lower supported rate. That narrows the search to an actual memory or scheduling dependency.
When ESP-DL is the better experiment
ESP-DL provides another route if the model and target operators fit its exporter. ESP-PPQ converts and quantises the model into .espdl for the supported target and settings. Espressif documents different quantisation behaviour across platforms. Export each build for the target it will run on, keep the calibration data and compare predicted results to the appropriate reference. Treat this as a separate test from the same-flatbuffer TFLM experiment. ESP-DL quantisation guide
For an ESP-DL build, use its documented model testing and memory profiling to see how much goes into internal RAM, PSRAM and flash. Keep the profile next to the load settings. An ESP-DL memory report and a TFLM arena size are different measurements, so compare the whole application’s available memory at equivalent stages as well. The port you intend to ship needs to fit with the rest of its services. ESP-DL model testing and profiling
If one path wins on inference time and the other wins on end-to-end latency, inspect their input work. It may be a software copy or a different resize, or one model may have a smaller input. Keep the accuracy target fixed when deciding which implementation to deploy. A pipeline that changes the model, runtime and camera format together is a valid product experiment if you record all of those changes.
Find the cause of a slow or failed run
If AllocateTensors() fails, start with the first diagnostic line. A missing registration or schema mismatch calls for a different fix from an arena allocation failure. Inspect the actual largest suitable free block and verify that the requested aligned size fits before changing the graph. Then check the arena planner output. It may be an operator’s scratch requirement that pushes the model over the limit.
If only the optimised variant misbehaves, confirm the outputs against the reference path using exactly the same input bytes. Check resolved library versions, target and whether alignment and supported shapes match the fast path. Keep a minimal test case. For an S31 issue, record invocation task affinity and compare that with what your port documents about SIMD-capable execution. If the debug build works but the deployment build fails under load, also inspect stack use and task ownership.
If warm latency is fine and the device misses its deadline anyway, trace the pipeline before raising the CPU clock. You might be waiting on audio capture, converting a camera buffer twice, or spending most of the time moving output onto a screen. Set a timestamp at each boundary. Remove one avoidable copy or reduce one excessive input dimension, rerun the fixture, then check the task metric again.

Record what you would use to choose the board
Fill each row from a real run. Repeat with the model that matters to you and duplicate rows for different placements or runtime versions. Free memory after peripherals start, arena capacity and measured latency need to be recorded on the same configuration. Keep raw reports and fixture hashes in the bench record.
| Target and kernel path | Actual arena bank | Reserved/used arena bytes | Largest internal block after setup | Median/p95 Invoke ms | Passed/attempted |
|---|---|---|---|---|---|
| S3 reference | |||||
| S3 ESP-NN | |||||
| S31 reference | |||||
| S31 ESP-NN |
| Application scenario | Capture and prep ms | Invoke ms | Output ready ms from start | Missed jobs |
|---|---|---|---|---|
| S3 representative load | ||||
| S31 representative load |
If the existing S3 build fits with margin and meets the worst useful response time, the S3 is a sensible baseline for that project. For a new build that needs more PSRAM or a vision or audio path that can use an S31 peripheral, test the S31 with that workload and measure what it changes. Same model first, real application afterwards. Those two sets of results tell you where the time and RAM actually go.

