Skip to content

perf: stop TLS retry storm, stream-parse JSON with a filter - #94

Merged
MatixYo merged 1 commit into
MatixYo:mainfrom
dreamiurg:perf/tls-timeout-and-streaming-json
Sep 24, 2026
Merged

MatixYo merged 1 commit into
MatixYo:mainfrom
dreamiurg:perf/tls-timeout-and-streaming-json

Conversation

@dreamiurg

Copy link
Copy Markdown
Contributor

Two problems in the ADS-B fetch path, both visible as UI stalls on an ESP32-C3.

TLS retry storm. The connect timeout was 200 ms — far too short for a TLS handshake to opendata.adsb.fi. performGetWithPoll therefore almost always failed and retried in a tight loop until the 10 s request deadline, opening a fresh handshake each time. Every poll cycle burned seconds of CPU and heap on handshakes that were killed just before they could finish. Now: 5000 ms connect timeout and a single attempt (kConnectAttempts = 1). If a connect stalls, the poll cycle gives up and the next one retries 3 s later, rather than blocking the display. The pollNetwork() call before the GET is kept.

Whole response buffered as a String. readResponseBodyWithPoll accumulated the entire JSON body into a heap String, which was then parsed into a JsonDocument — the payload existed twice in RAM, and a busy sector's response is large. Replaced with deserializeJson(doc, http.getStream(), DeserializationOption::Filter(filter)): ArduinoJson parses straight off the socket and the filter keeps only the fields actually rendered (lat, lon, headings, speeds, altitudes, flight, hex, t, category). No intermediate String, and the document holds a small fraction of the response.

Also: request timeout 10000 ms to 6000 ms, and the now-unused performGetWithPoll/readResponseBodyWithPoll are deleted. The two paths are consolidated into one httpGetJson helper.

User impact: the radar stops freezing for seconds at a time on flaky WiFi, and peak heap use during a fetch drops substantially — the difference between working and heap-exhausting when many aircraft are in range.

Tested: builds for env:supermini; ran on an ESP32-C3 Super Mini + GC9A01 (combined with other local changes).

🤖 Generated with Claude Code

https://claude.ai/code/session_017qjXYQiTkbgyVV7ZzvKzA3

The 200 ms connect timeout was too short for a TLS handshake, so every
poll retried handshakes in a loop until the 10 s deadline. Use a 5000 ms
connect timeout and a single attempt; a stalled connect is retried by the
next poll instead of blocking the UI.

Parse the response straight off the socket with a DeserializationOption
Filter that keeps only the rendered fields, instead of buffering the whole
body into a String and parsing that. Drop performGetWithPoll and
readResponseBodyWithPoll in favor of one httpGetJson helper.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017qjXYQiTkbgyVV7ZzvKzA3
@MatixYo
MatixYo merged commit 9d85778 into MatixYo:main Sep 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants