One Serial.println() is slowing down your loop
With the Arduino IDE defaults, Serial on the ESP32-S3 is the chip's UART. A print returns quickly while the hardware FIFO has room, but once it is full, every print waits for the wire, and loop() runs at the speed set in Serial.begin().
In short
- An almost empty
loop()runs about 884,000 times a second. With one 13-byteSerial.println()per pass at 115200 baud it runs 885 times. - Each byte is 10 bits on the wire (8N1), so a 13-byte line takes 130 bits: 1.13 ms at 115200 baud. Measured: 1,128.23 µs per print.
- A print that fits in the 128-byte TX FIFO takes about 89 µs. When the FIFO is full, the next print waits until it is almost empty: about 11 ms at 115200 baud.
- One print per pass: about 74 passes per second at 9600 baud, 885 at 115200, about 7,100 at 921600. Closing Serial Monitor changes nothing.
- What helps: print less often, raise the baud rate on both sides.
Serial.setTxBufferSize()beforebegin()splits the long waits, but the average rate stays the same.
One line, a thousand times fewer passes
This loop() does almost nothing: it increments a counter and checks a 64-bit timer once per pass to report the count every second.
volatile float temp = 23.45f;
void loop() {
n++;
Serial.print("temp: "); Serial.println(temp); // the added line
if (esp_timer_get_time() >= tNext) { /* store n, reset it */ }
}
Without the print, it runs about 884,000 times a second on an ESP32-S3 at 240 MHz. With one print per pass at 115200 baud, it runs 885 times. The CPU work of the print takes microseconds. The rest of the time is spent waiting.
Serial is a UART
In arduino-esp32, what Serial means depends on the USB CDC On Boot option. For the ESP32-S3 it defaults to Disabled, and then Serial is Serial0, the chip's UART0:
// arduino-esp32 3.3.12, cores/esp32/HardwareSerial.h
#else // !ARDUINO_USB_CDC_ON_BOOT -- Serial is used from UART0
#define Serial Serial0
On many dev boards, including the one used here, a separate USB-serial chip turns the UART's TX and RX pins into the port you see on the computer. On this board it is a CH343 (USB ID 1a86:55d3):
ESP32-S3: UART0 → TX pin → USB-serial chip (CH343) → USB → PC
A UART is slow by CPU standards. The number in Serial.begin() is the baud rate, and for a UART that is bits per second: at 115200 baud it sends 115,200 bits a second.
Ten bits per byte
A UART frame starts with one start bit, carries the data bits and ends with one or more stop bits. The ESP32-S3 Technical Reference Manual allows 5 to 8 data bits and 1, 1.5 or 2 stop bits. Arduino uses SERIAL_8N1 by default: 8 data bits, no parity, 1 stop bit. So each byte takes 1 + 8 + 1 = 10 bits on the wire.
The test line is "temp: 23.45", 11 characters, plus the \r\n that println() adds:
13 bytes × 10 bits = 130 bits
130 bits ÷ 115,200 bit/s = 1.128 ms per line
The measurement matches: in steady state, with one print per pass at 115200 baud, each pass took 1,128.23 µs. The measured rate matches the 130-bits-per-line calculation to within about 0.2%.
| Baud | Measured, µs per print | Calculated, 130 bits ÷ baud |
|---|---|---|
| 9600 | 13,512.02 | 13,541.7 |
| 115200 | 1,128.23 | 1,128.5 |
| 921600 | 141.00 | 141.1 |
The 128-byte FIFO
A print does not wait for the wire. The UART has a hardware transmit FIFO of 128 bytes (SOC_UART_FIFO_LEN in ESP-IDF). The print puts its bytes there and returns, and the UART shifts them out on its own. The Arduino reference describes the same contract for Serial.write():
“If there is enough empty space in the transmit buffer, Serial.write() will return before any characters are transmitted over serial. If the transmit buffer is full then Serial.write() will block until there is enough space in the buffer.”
There is no software buffer in front of the FIFO by default. The arduino-esp32 docs say “Default TX buffer size is 0 (no buffering)”, and for that case the ESP-IDF UART driver documents that the TX function blocks the task until all the data has been sent out, or at least pushed into the TX FIFO.
What the first 40 calls look like
To see this, the test sketch waits until the line is quiet, then times each of the next 40 print calls with the CPU cycle counter. At 115200 baud (all three runs gave the same picture):
| Calls | Time per call | What happens |
|---|---|---|
| 1 | 113.6 µs | FIFO empty, bytes go straight in |
| 2–10 | 89.4 µs each | still room in the FIFO |
| 11 | 11,152 µs | FIFO full: waits until it is almost empty |
| next 10 | ~89 µs each | room again |
| next | 11,137 µs | full again |
| next 10 | ~89 µs each | |
| next | 11,164 µs |
Note that the long call does not wait for one line to leave. It waits about 11 ms, roughly ten lines' worth, and after it the next ten calls are fast again. On average, the loop runs at the speed of the wire.
The pattern is the same at the other speeds, scaled:
- 9600 baud: 113.6 µs, then 89.4 µs × 9, then a wait of 133,046 µs (133 ms), nine calls of 89 µs, then 132,524 µs, and so on.
- 921600 baud: almost every call takes 89 µs. The first wait comes only at call 28 and lasts 1,494 µs. Here the wire nearly keeps up with the CPU: 141 µs per line on the wire against 89 µs per call.
A call that fits in the FIFO costs about 89 µs regardless of the baud rate. That is the CPU time of the print itself.
Why it waits until the FIFO is almost empty
The source code explains the long waits:
- arduino-esp32 installs the UART driver without a TX buffer:
_txBufferSize(0)inHardwareSerial.cpp, passed on touart_driver_install(). - Without a TX buffer, ESP-IDF's
uart_tx_all()(v5.5.6,uart.c) puts as many bytes into the FIFO as fit. If not everything fits, it setstx_waiting_fifoand waits on a semaphore. The semaphore is given by theUART_INTR_TXFIFO_EMPTYinterrupt. - That interrupt fires when the FIFO drops below a threshold of 10 bytes:
UART_EMPTY_THRESH_DEFAULT (10)in ESP-IDF, and.txfifo_empty_intr_thresh = 10in arduino-esp32'sesp32-hal-uart.c.
So a print that does not fit sleeps until the FIFO has drained from full to under 10 bytes. A simple model of this (128 bytes, wait until fewer than 10 remain) gives 10.3 ms at 115200 baud and 123 ms at 9600. The measured waits are 11.2 ms and 133 ms. The difference of about 8% was not investigated.
The baud rate is a speed limit
In steady state the wire sets the pace: one 13-byte line per pass means at most baud ÷ 130 passes per second. That is what the real Arduino loop() did (3 runs of 5 seconds per configuration):
| Baud | No print | One println() per pass | baud ÷ 130 |
|---|---|---|---|
| 9600 | 884,000 | 79 / 69 alternating, 74 on average | 73.8 |
| 115200 | 884,000 | 885 (first second: 893–897) | 886.2 |
| 921600 | 884,000 | 7,086–7,101 | 7,089.2 |
The host counted the received lines independently, by its own clock: 887.7–888.2 lines per second at 115200 (calculated 886.2), 7,094–7,095 at 921600 (calculated 7,089), and 76.2 at 9600. At 9600 the lines arrive in bursts inside USB packets, so over a short window that number is only good to about ±3%.
Closing the monitor doesn't help
The UART sends every bit whether anyone is listening or not. With no flow control (Arduino's default is UART_HW_FLOWCTRL_DISABLE), it has no way to know that a receiver exists.
To check this, the test ran with the port closed. The upload tool resets the board and closes the port, the test runs right after boot with nobody listening, and the result is saved to NVS. When the host opens the port again and the board restarts, it prints the saved result.
Port open
1,128.23 µs per print
Port closed
1,128.23 µs per print
With the port closed: 2,667 passes in 3 seconds, first calls 89.3 µs × 9 and then a wait of 11,154 µs, the same as with the port open. The host received no temp: lines during any of the three runs, so the test really ran without a listener. Three runs out of three gave the same result.
A first attempt that simply closed the port from the host and reopened it later was not valid: reopening the port reset the board, so the test ran with the port open. Only the NVS-based runs are counted.
What helps
1. Print less often
Ten times a second is plenty for a human reading the monitor:
unsigned long lastPrint = 0;
void loop() {
// ... the real work ...
if (millis() - lastPrint >= 100) { // print less often
lastPrint = millis();
Serial.println(temp);
}
}
2. Raise the baud rate, on both sides
Serial.begin(921600); // and select 921600 in Serial Monitor too
At 921600 baud the same loop ran about 7,100 times a second instead of 885.
3. A TX buffer smooths bursts, not the average
Serial.setTxBufferSize() gives the driver a software buffer in front of the FIFO. It must be called before begin(); the arduino-esp32 docs say “This function must be called before begin() to take effect.”
Serial.setTxBufferSize(1024); // before begin(): smooths bursts only
Serial.begin(115200);
Measured at 115200 baud with a 1024-byte buffer:
| No TX buffer | 1024-byte TX buffer | |
|---|---|---|
| Steady state, µs per print | 1,128.23 | 1,125.85 |
| Fast call | ~89 µs | ~101 µs |
| Long waits | ~11 ms | 3.4–5.7 ms |
The buffer breaks the long waits into shorter ones, which helps if your code prints in occasional bursts. But if it prints on every pass, the average is still the speed of the wire.
The exception: native USB
Everything above is about the default setup, where Serial is UART0 behind a USB-serial chip. If your board talks to the computer through the ESP32-S3's own USB port and you set Tools → USB CDC On Boot → Enabled, Serial goes over the chip's USB Serial/JTAG controller instead. There is no UART in the way, and the baud rate is ignored:
- The ESP32-S3 TRM lists
SET_LINE_CODINGfor the USB Serial/JTAG controller as “Accepted but ignored (dummy)”. - arduino-esp32's
HWCDC.cpplogs a warning when you try to change it: “USB Serial/JTAG baud rate is set by the USB standard; updateBaudRate(%lu) has no effect”.
That path has its own rules and was not measured here: the cable on the test board was connected to the CH343 port.
Caveats
- All numbers are from one ESP32-S3 board with a CH343 USB-serial chip, arduino-esp32 3.3.12 with default settings, at 240 MHz. Some boards have only the native USB port, and then the previous section applies instead.
- The cost depends on the line length. The test line is 13 bytes; a longer line takes proportionally longer on the wire (10 bits per byte at 8N1).
- The “almost empty” threshold model explains the pattern of the waits, but the measured waits are about 8% longer than the model predicts. The page shows the measured values.
- “Ten times a second is plenty” is a rule of thumb for reading the monitor, not a measured limit.
Test setup and code
| Board | ESP32-S3 at 240 MHz, USB through a CH343 USB-serial chip (1a86:55d3), not the chip's native USB |
| Core | arduino-esp32 3.3.12, board esp32:esp32:esp32s3, all settings default: USB CDC On Boot: Disabled, so Serial = Serial0 = UART0 |
| Print under test | Serial.print("temp: "); Serial.println(temp); with volatile float temp = 23.45f: 13 bytes including \r\n |
| Speeds | 9600, 115200, 921600 baud; 115200 also with Serial.setTxBufferSize(1024) |
| Method | cost.ino: each of the first 40 calls timed with the CPU cycle counter, then 3 s of steady state timed with esp_timer and cycles. loops.ino: passes per second of the real loop(), 5 s without and 5 s with a print. The host counted received lines by its own clock. |
| Repeats | Every configuration 3 times; the repeats agreed to fractions of a percent (to single cycles in the cycle counts) |
| Port closed | cost.ino built with HOLD=2: the test runs right after upload with the port closed, the result goes to NVS and is printed on the next boot |
// BAUD and TXBUF are passed with -D.
#include "esp_timer.h"
#include "esp_cpu.h"
volatile float temp = 23.45f; // volatile: no compile-time formatting
const int N_CALLS = 40;
uint32_t callCycles[N_CALLS];
void setup() {
if (TXBUF) Serial.setTxBufferSize(TXBUF);
Serial.begin(BAUD);
delay(300);
// Per-call cost of the first N_CALLS println() after the line has gone quiet
Serial.flush(); delay(100);
for (int i = 0; i < N_CALLS; i++) {
uint32_t c0 = esp_cpu_get_cycle_count();
Serial.print("temp: "); Serial.println(temp);
callCycles[i] = esp_cpu_get_cycle_count() - c0;
}
Serial.flush(); delay(100);
// Steady state: loop that prints every iteration, 3 s
uint32_t loops = 0; int64_t t0 = esp_timer_get_time();
while (esp_timer_get_time() - t0 < 3000000) {
Serial.print("temp: "); Serial.println(temp);
loops++;
}
int64_t dt = esp_timer_get_time() - t0;
// ... report dt / loops and callCycles[i] / CPU MHz: see the full file
}
void loop() {}
Also: loops.ino, which counts passes per second of the real loop() without and with a print.
Sources
- ESP32-S3 Technical Reference Manual v1.8, chapter 26 UART “A frame starts with one START bit, and ends with STOP bits which can be 1, 1.5, or 2 bits long … The actual data length can be anywhere between 5 ~ 8 bits” · “the RAM is divided into 8 blocks, each having 128 × 8 bits”
- ESP32-S3 Technical Reference Manual v1.8, USB Serial/JTAG controller, table 33.3-1 “SET_LINE_CODING — Accepted but ignored (dummy)”
- ESP-IDF: soc_caps.h (ESP32-S3)
#define SOC_UART_FIFO_LEN (128) - ESP-IDF UART driver and driver/uart.h “If set to zero, driver will not use TX buffer, TX function will block task until all data have been sent out.” ·
uart_write_bytes: “…until all the data have been sent out, or at least pushed into TX FIFO” - ESP-IDF v5.5.6: components/esp_driver_uart/src/uart.c
uart_tx_all()waits ontx_fifo_sem, given by theUART_INTR_TXFIFO_EMPTYinterrupt;UART_EMPTY_THRESH_DEFAULT (10) - arduino-esp32 Serial API (serial.rst) “Default TX buffer size is 0 (no buffering).” · “This function must be called before begin() to take effect.”
- arduino-esp32 3.3.12: HardwareSerial.h, HardwareSerial.cpp, esp32-hal-uart.c,
boards.txt#define Serial Serial0without USB CDC On Boot ·_txBufferSize(0)·.txfifo_empty_intr_thresh = 10·esp32s3.menu.CDCOnBoot.default=Disabled - arduino-esp32: Tools menu guide “This option can be used as well for debugging via the Serial Monitor using CDC instead of the UART0.”
- arduino-esp32 3.3.12: HWCDC.cpp “USB Serial/JTAG baud rate is set by the USB standard; updateBaudRate(%lu) has no effect”
- Arduino reference: Serial.write() (source) “If the transmit buffer is full then Serial.write() will block until there is enough space in the buffer.”
Video
A short video on the same topic is on the ESPSSS YouTube channel (3:11, 2026-11-23). This page goes into more detail.
Also as a YouTube Short.