Performance tweaks

Optimization Walkthrough: 83kHz ADC Streaming
Achievement
Maximized the ESP32-C6 ADC continuous mode performance, achieving 83kHz stable streaming (hardware max) with 0 dropped packets.

Key Optimizations
1. Architecture: Zero-Copy Streaming
Change: Removed ws_sender_task and RingBuffer.
Mechanism:
adc_read_task
 sends binary WebSocket frames directly.
Benefit: Reduced context switching and memory copies (approx +25% throughput).
2. Frontend: Decoupled Rendering
Change: Replaced onmessage -> draw() with requestAnimationFrame loop.
Mechanism: ws.onmessage only updates the data buffer. The browser draws at 60Hz.
Benefit: Eliminated UI jitter caused by drawing >60 times per second.
3. Latency: Power Save Disabled
Change: esp_wifi_set_ps(WIFI_PS_NONE)
Mechanism: Keeps the Wi-Fi radio active 100% of the time, preventing ~100ms sleep cycles.
Benefit: Eliminated periodic latency spikes which caused buffer overflows.
4. Buffering: Throughput Tuning
Change: ADC_READ_LEN increased 1024 -> 4096 bytes.
Change: Driver buffer max_store_buf_size increased 1024 -> 16384 bytes.
Benefit: Provided ~30ms of safety margin for Wi-Fi blocking operations, preventing driver-level overflows.
Final Configuration
Sample Rate: Up to 83kHz.
Packet Size: 4096 bytes (batched).
Latency: <50ms end-to-end.
Drops: 0.
This commit is contained in:
Matt
2025-12-13 10:32:40 +00:00
parent d3dd05edc5
commit 74dd3646b5
2 changed files with 73 additions and 91 deletions

View File

@@ -151,7 +151,7 @@ canvas.addEventListener('click', (event) => {
time: timeOffset
};
draw();
// draw(); // Removed: Animation loop handles this
}
});
@@ -194,7 +194,7 @@ function connect() {
const arr = new Uint16Array(event.data);
if (arr?.length) {
processData(arr);
draw();
// draw(); // Removed: Drawing is now handled by animation loop
}
} catch (e) {
console.error('Parse error:', e);
@@ -202,6 +202,16 @@ function connect() {
};
}
// Animation loop
function animationLoop() {
if (!isFrozen) {
draw();
}
requestAnimationFrame(animationLoop);
}
// Start the loop
requestAnimationFrame(animationLoop);
function processData(/** @type Uint16Array */newData) {
if (isFrozen) {
return; // Skip updating the buffer when frozen
@@ -439,8 +449,8 @@ function loadStoredConfig() {
document.getElementById('reconnectBtn').addEventListener('click', connect);
document.querySelectorAll('#sampleRate, #bitWidth, #atten, #testHz, #triggerLevel').forEach(input => input.addEventListener('change', setParams));
document.getElementById('resetBtn').addEventListener('click', () => {
localStorage.clear();
window.location.reload();
localStorage.clear();
window.location.reload();
});
setParams();
connect();