# Building a 60fps Self-Hosted Mobile IDE in Pure Python + Vanilla JS (2.8ms Delta Sync — Roast My Architecture)

> 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: 2026-12-06 08:39:41+00:00

**Recommendation:** 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.
More in the playbook "Designing agent systems": <https://wpnews.pro/playbooks/agent-architecture>

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:

`innerHTML` repaints blinked on every step`<details>` tool-trace accordions shut unless carefully tracked.`.jsonl` transcripts (`4.9 MB+`) from byte `0`
Here 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.

`v7.2`):` v7.0.0-beta``(size, mtime_ns)` Segment Cache (`2.8ms` Delta)
Long 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.

Instead, each conversation segment is keyed by `(file_size, st_mtime_ns)` in RAM, and active transcripts seek straight to the last `680 KB` window:

``` python
@staticmethod
def _read_jsonl_tail(tpath: Path, max_lines: int = 340, max_bytes: int = 680_000):
    size = tpath.stat().st_size
    if size <= 0:
        return [], 0
    with tpath.open("rb") as f:
        if size > max_bytes:
            f.seek(size - max_bytes)
            raw_chunk = f.read()
            nl = raw_chunk.find(b"\n")
            if nl != -1:
                raw_chunk = raw_chunk[nl + 1:]
            lines = raw_chunk.decode("utf-8", errors="replace").splitlines()
            return lines[-max_lines:], max(len(lines), size // 900)
        lines = f.read().decode("utf-8", errors="replace").splitlines()
        return lines[-max_lines:], len(lines)
```

Pairing this with `?since=<composite_sig>` means unchanged delta checks return `{"unchanged": true}` in **`2.8ms`** locally and <60 bytes on the wire.

`250ms` SSE + Dual-Container Optimistic Outbox
Over 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:

```
self.send_header("Cache-Control", "no-cache, no-transform")
self.send_header("X-Accel-Buffering", "no")
self.end_headers()
self.wfile.write((": stream-open " + (" " * 1024) + "\n\n").encode("utf-8"))
self.wfile.flush()
```

On 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`):

``` js
function reconcileSlots(container, htmlItems) {
  const children = container.children;
  for (let i = 0; i < htmlItems.length; i++) {
    const html = htmlItems[i];
    const h = fastHash(html);
    if (i < children.length) {
      if (children[i].getAttribute('data-hash') !== h) {
        children[i].setAttribute('data-hash', h);
        children[i].innerHTML = html;
      }
    } else {
      const slot = document.createElement('div');
      slot.className = 'turn-slot';
      slot.setAttribute('data-hash', h);
      slot.innerHTML = html;
      container.appendChild(slot);
    }
  }
  while (container.children.length > htmlItems.length) {
    container.removeChild(container.lastChild);
  }
}
```

Historical 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.

`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
I'd love genuine code/UX critiques from folks building dev tools, mobile PWAs, or local-first bridges:

I'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!
