Working checklist of every change required to eliminate the dropped-frame jitter on the
Raspberry Pi 4B kiosk (bits_n_bytes_ui, flutter-pi / DRM-KMS). Each item is tagged
[UI] (CPU/Dart thread — profilable on any machine) or [GPU] (raster thread — only
truthfully measurable on the Pi). Diagnose with flutter run --profile + DevTools →
Performance: top bar = UI thread, bottom bar = raster thread.
Status legend: ✅ applied · ⬜ not yet applied
File: lib/services/serial_service_real.dart — _onJsonDataReceived
Problem: currentBuffer += String.fromCharCodes(data) plus repeated substring and a
char-by-char brace scan over the whole buffer on every chunk. Runs on the main isolate via
SerialPortReader, so it fights rendering on every byte the ESP/Jetson sends.
Fix applied: single forward index scan that tracks brace depth, dispatches each complete
JSON object via _dispatchJson, and keeps only the unconsumed tail in _jsonBuffers. No
per-chunk +=/substring rebuilds. Removed the dead _accumulatedBuffer field and the unused
dart:developer import.
Further improvement (optional): move the read+parse into a background
Isolate/computeand push only parsed objects back to the UI isolate.
Files: lib/pages/welcome.dart, lib/services/log_service.dart, lib/pages/admin.dart
Problem: anonymous listeners were added but never removed, so they stacked. welcome.dart
added a fresh NFC listener from initState, the refresh button, and the 404 branch — one
packet then fired N handlers → N logins, N rebuilds, ever-growing CPU (jitter that worsens the
longer the kiosk runs).
Fix applied:
welcome.dart: register_onNfcDataonce ininitState; refresh button and 404 branch now only call_sendNfcInit()(send the init packet) instead of re-adding a listener;disposeremoves_onNfcData.admin.dart: named_onEspState, added ininitState, removed indispose.log_service.dart:init()is now idempotent (_initializedguard) and registers named_onEspState/_onJetsonStatelisteners.
Files: lib/util.dart, pubspec.yaml, assets/fonts/
Problem: GoogleFonts.getTextTheme downloaded font files over HTTP on first launch →
network-dependent startup stall + reflow when the fonts swapped in.
Fix applied: removed the google_fonts dependency; bundled the TTFs as assets
(Roboto-Variable.ttf, IBMPlexMono-{Regular,Medium,SemiBold,Bold}.ttf) and declared them under
flutter: fonts:. createTextTheme now applies the bundled families directly (Roboto = body,
IBM Plex Mono = display), so glyphs are present from the first frame.
Files: lib/components/cart_item.dart, lib/components/shelf.dart, lib/pages/receipt.dart
Problem: blur forces an offscreen saveLayer/compositing pass — the single most expensive op
on the Pi's GPU — and in the cart it happened per list item, rebuilt on every Jetson packet.
Fix applied: replaced each blurred BoxShadow with a flat 1px
Border.all(color: outlineVariant) (cart item, shelf, receipt card) and a flat left BorderSide
for the receipt sidebar. No offscreen layers.
File: lib/components/cart_item.dart:38
Decodes the full-size image (displayed at 100×100) and re-decodes on cache eviction; the cart list
is rebuilt (cart = List.from(cart)) on every Jetson packet.
Fix: add cacheWidth: 100 for a downsampled decode; consider cached_network_image or
pre-seeding the image cache.
File: lib/services/log_service.dart
vn.value = [...vn.value, msg] + removeAt(0) are both O(n), plus an unconditional log() per
event. Serial data is logged per packet → constant allocation/GC churn.
Fix: fixed-size ring buffer / ListQueue; gate verbose log() behind a debug flag; throttle.
File: lib/services/serial_service_real.dart (espState.value = jsonData)
Always notifies, waking LogService.parseJsonChanges, the CartPage door listener, and AdminPage —
per packet.
Fix: debounce/coalesce UI-facing updates (~10–20 Hz) and skip notifying on unchanged fields.
- ⬜
CartItem/ShelfareStatefulWidgetwith no state → makeStatelessWidget. - ⬜ Add
constconstructors to static subtrees to cut rebuilds. - ⬜
MediaQuery.sizeOf(context).widthread inside item builders (cart_item.dart:16,shelf.dart:85) → hoist above the builder. - ⬜
SvgPicture.assetrasterizes vectors at runtime → pre-rasterize static logos to PNG. - ⬜
cart = List.from(cart)after mutating in place (cart.dart) is a redundant allocation.
- Measure, don't guess. Reproduce with
flutter run --profileon the Pi and watch the UI vs raster split before/after each change. UI-thread items (1, 2, 3, 6, 7) verify on any machine; GPU items (4, 5) need the Pi to confirm. - Do not judge jitter by eye over a
--stream(Sunshine/Moonlight) session — the encoder adds latency that masks/fakes smoothness. Use on-device DevTools metrics. bnb run simvalidates the serial/framing path cross-platform (no GPU) in seconds.bnb run devruns the full kiosk on the Pi with real GPU + hot reload for final sign-off.