{"slug": "building-a-60fps-self-hosted-mobile-ide-in-pure-python-vanilla-js-2-8ms-delta-my", "title": "Building a 60fps Self-Hosted Mobile IDE in Pure Python + Vanilla JS (2.8ms Delta Sync — Roast My Architecture)", "summary": "A developer built PocketAGY, a self-hosted mobile IDE (iOS PWA plus a universal Android WebView APK) that controls AI coding agents running on a desktop over Wi-Fi and 5G, using only the Python standard library and framework-free Vanilla JS. The stack keys conversation segments by (file_size, st_mtime_ns) and reads only the last 680 KB of JSONL transcripts, returning unchanged delta checks in 2.8ms and under 60 bytes on the wire, while a 250ms SSE stream with a 1 KB comment preamble defeats proxy buffering and dual feed/outbox containers reconciled by 32-bit FNV-1a hashes keep chat flicker-free at 60fps. The project also includes a pure-Python QR pairing module with Reed-Solomon ECC and is in a free open beta.", "body_md": "When building **PocketAGY** — a self-hosted Mobile IDE (iOS PWA + Universal Android WebView APK) to control AI coding agents running on my desktop over Wi-Fi and 5G — my early prototype felt noticeably clunky on a real phone over cellular:\n\n`innerHTML` repaints blinked on every step`<details>` tool-trace accordions shut unless carefully tracked.`.jsonl` transcripts (`4.9 MB+`) from byte `0`\nHere is how I re-engineered the stack in **pure Python stdlib + zero-framework Vanilla JS (`v7.2`)** to hit **` 2.8ms` delta checks** and **60fps flicker-free chat** — plus a **Live Sandbox & Free Open Beta** if you want to poke holes in it.\n\n`v7.2`):` v7.0.0-beta``(size, mtime_ns)` Segment Cache (`2.8ms` Delta)\nLong agent sessions easily exceed `5 MB` of JSONL logs (`2,300+` tool calls and thoughts). Parsing the whole file on every `250ms` stream check is wasteful.\n\nInstead, each conversation segment is keyed by `(file_size, st_mtime_ns)` in RAM, and active transcripts seek straight to the last `680 KB` window:\n\n``` python\n@staticmethod\ndef _read_jsonl_tail(tpath: Path, max_lines: int = 340, max_bytes: int = 680_000):\n    size = tpath.stat().st_size\n    if size <= 0:\n        return [], 0\n    with tpath.open(\"rb\") as f:\n        if size > max_bytes:\n            f.seek(size - max_bytes)\n            raw_chunk = f.read()\n            nl = raw_chunk.find(b\"\\n\")\n            if nl != -1:\n                raw_chunk = raw_chunk[nl + 1:]\n            lines = raw_chunk.decode(\"utf-8\", errors=\"replace\").splitlines()\n            return lines[-max_lines:], max(len(lines), size // 900)\n        lines = f.read().decode(\"utf-8\", errors=\"replace\").splitlines()\n        return lines[-max_lines:], len(lines)\n```\n\nPairing this with `?since=<composite_sig>` means unchanged delta checks return `{\"unchanged\": true}` in **`2.8ms`** locally and <60 bytes on the wire.\n\n`250ms` SSE + Dual-Container Optimistic Outbox\nOver 5G reverse proxies, small initial `text/event-stream` headers often sit in an edge buffer until ~1 KB accumulates. Sending a single `1 KB` comment preamble on stream open flushes the tunnel immediately:\n\n```\nself.send_header(\"Cache-Control\", \"no-cache, no-transform\")\nself.send_header(\"X-Accel-Buffering\", \"no\")\nself.end_headers()\nself.wfile.write((\": stream-open \" + (\" \" * 1024) + \"\\n\\n\").encode(\"utf-8\"))\nself.wfile.flush()\n```\n\nOn the frontend, instead of shipping React/Preact, I split the feed into two sibling containers (`#feedSlots` for server-confirmed turns and `#outboxSlots` for in-flight mobile prompts) and reconcile each slot via 32-bit FNV-1a hashes (`data-hash`):\n\n``` js\nfunction reconcileSlots(container, htmlItems) {\n  const children = container.children;\n  for (let i = 0; i < htmlItems.length; i++) {\n    const html = htmlItems[i];\n    const h = fastHash(html);\n    if (i < children.length) {\n      if (children[i].getAttribute('data-hash') !== h) {\n        children[i].setAttribute('data-hash', h);\n        children[i].innerHTML = html;\n      }\n    } else {\n      const slot = document.createElement('div');\n      slot.className = 'turn-slot';\n      slot.setAttribute('data-hash', h);\n      slot.innerHTML = html;\n      container.appendChild(slot);\n    }\n  }\n  while (container.children.length > htmlItems.length) {\n    container.removeChild(container.lastChild);\n  }\n}\n```\n\nHistorical bubbles stay 100% untouched in the DOM (text selection and open `<details>` tool logs never reset), while `#outboxSlots` keeps the user's message pinned until the exact turn appears in `#feedSlots` in the same frame.\n\n`qr_svg.py` implements GF(256) Reed-Solomon ECC + ISO/IEC 18004 Byte-mode matrix masking in ~170 lines of pure Python so `http://127.0.0.1:8787/pair` works without `pillow` or `qrcode` C-wheels.`@tabzipsa` on an earlier post, the Free Open Beta physically excludes `pro_runtime.py`, Pro certificates are signed with `secp256r1`) ECDSA\nI'd love genuine code/UX critiques from folks building dev tools, mobile PWAs, or local-first bridges:\n\nI'm giving **free lifetime Pro licenses** ([Gumroad link for reference](https://datphantom.gumroad.com/l/pocket-agy-mobile)) to the sharpest technical critiques and bug reports!", "url": "https://wpnews.pro/news/building-a-60fps-self-hosted-mobile-ide-in-pure-python-vanilla-js-2-8ms-delta-my", "canonical_source": "https://dev.to/thnh_tphan_3fb70b2963/building-a-60fps-self-hosted-mobile-ide-in-pure-python-vanilla-js-28ms-delta-sync-roast-my-291f", "published_at": "2026-12-06 08:39:41+00:00", "updated_at": "2026-12-06 08:44:28.575415+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools", "ai-products"], "entities": ["PocketAGY", "Python", "Vanilla JS", "Reed-Solomon", "FNV-1a", "secp256r1"], "also_reported_by": [], "takeaway": "Keying transcript segments by (file_size, st_mtime_ns) and seeking to the last 680 KB of JSONL cuts unchanged delta checks to 2.8ms and under 60 bytes, while hash-reconciled feed/outbox containers avoid full innerHTML repaints.", "recommendation": {"advice": "Tail-read large JSONL agent transcripts by byte offset and cache segments on (size, mtime_ns), and reconcile DOM slots by content hash instead of repainting the whole feed.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/building-a-60fps-self-hosted-mobile-ide-in-pure-python-vanilla-js-2-8ms-delta-my", "markdown": "https://wpnews.pro/news/building-a-60fps-self-hosted-mobile-ide-in-pure-python-vanilla-js-2-8ms-delta-my.md", "text": "https://wpnews.pro/news/building-a-60fps-self-hosted-mobile-ide-in-pure-python-vanilla-js-2-8ms-delta-my.txt", "jsonld": "https://wpnews.pro/news/building-a-60fps-self-hosted-mobile-ide-in-pure-python-vanilla-js-2-8ms-delta-my.jsonld"}}