perf: cut dev-mode memory in the frontend and telemetry paths

Merged
FA
1mo ago
+105-31

Summary

Two dev-mode memory reductions, measured on a blank app.

  • Frontend toolchain: set MIMALLOC_ARENA_EAGER_COMMIT=0 for the vite dev server and the reflex export build (exec.frontend_env()). Rolldown allocates through mimalloc, and with eager commit the arena it touches during dependency pre-bundling stays resident for the life of the dev server. A value already present in the environment wins.
  • Telemetry: _send_event posts through urllib.request instead of httpx, so backend workers never import httpx on their first error. The packaging imports in telemetry.py are lazy.

Measurements

PSS over the whole reflex run tree, page loaded once in headless Chrome, 15 s settle, cold = no .web/node_modules/.vite.

mainthis PR
node, cold~780 MB~460 MB
node, warm~415 MB~340 MB
total, cold~1118 MB~788 MB
total, warm~752 MB~668 MB
worker, first error+9 MB, 0.07 s (httpx import)+1 MB, 0.01 s

Python-side worker layout is unchanged here; #7079 covers forking.

Test plan

  • uv run pytest tests/units (8482 passed, 76.6% coverage)
  • ruff, pyright, pre-commit clean
  • reflex export --frontend-only builds with the new env
  • dev server starts and serves with the env var set

https://claude.ai/code/session_015Gi5wTWZNBA61pVDdPLu8u