perf(phase-1/m2.5): export memory measured on synthesized worst-case libraries

Phase 1 M2 task 5 (tools/DESKTOP_PHASE_PLAN.md §4): measure & record,
no redesign. New :core:data-jvm:backupMemory probe (2g heap) samples
heap-used at 1 ms during BackupBridge.exportPlain — the phone's own
export path — across four fresh libraries:

  24 MB data (3 att)  → peak 230 MB   |  2 MB text x2000 notes → 140 MB
  80 MB data (10 att) → peak 777 MB   | 320 MB data (40 att)  → OOM at -Xmx2g

Attachments drive memory (~9–10x allocation pressure: store load →
base64 String → UTF-8 bytes → JsonElement tree); note count alone is
trivial. The plan's 250 MB gate trips at ~25–30 MB of attachments, and
the phone (no largeHeap) shares the ceiling — a pre-existing Android
limitation, unchanged by the bridge extraction. The real library
exports at 366 KB ≈ 1000x headroom. Bonus: a ~1.6 GB library dies in
objectbox-java's DbFullException before the bridge ever sees it.

Verdict: record, don't redesign. Streaming formatVersion=2 stays parked
for Phase 2, required only if attachment libraries approach ~25 MB.
This commit is contained in:
Incido Developer committed 2026-10-05 19:48:02 +13:00
1 parent 52ccceb732
commit 9cb7fdbf58
3 files changed
+195

No files matched your search

+35
View File
@@ -426,6 +426,41 @@ same `:core:backup` codec — the remaining proof for task 4 is the
on-device leg (Waydroid: phone re-imports a desktop-made encrypted file
+ dedupe snackbar), tracked as M2 task 4b.
**M2 task 5 — export memory: MEASURED, recorded, no redesign (per plan).**
New `:core:data-jvm:backupMemory` probe synthesizes worst-case ObjectBox
libraries (fixed seed) and samples heap-used at 1 ms while
`BackupBridge.exportPlain` — the phone's own export path — runs:
```
heap ceiling : 2048 MB
phone-at-gate (20 notes, 3 att x 8 MB) | data≈ 24 MB → 520 ms | peak 230 MB (+219) | file 32 MB
many notes (2000 notes, no att) | data≈ 2 MB → 205 ms | peak 140 MB (+104) | file 3 MB
phone-heavy (100 notes, 10 att x 8 MB)| data≈ 80 MB → 1100 ms | peak 777 MB (+765) | file 106 MB
watch tier (200 notes, 40 att x 8 MB)| data≈320 MB → OutOfMemoryError at -Xmx2g
process peak RSS (VmHWM): 1707 MB
```
Findings:
- **Attachments, not note count, drive memory.** 2000 text notes cost
140 MB peak — trivial. Export allocation runs ~9–10x attachment bytes
(store load → base64 String → UTF-8 bytes → JsonElement tree ≈ four
live copies plus serializer churn).
- The plan's >250 MB gate trips at ≈25–30 MB of attachments. The phone
declares no `largeHeap`, so its default (~192–256 MB) heap OOMs around
the same point — a **pre-existing Android limitation**, unchanged by
Phase 1 (the bridge moved the code, not its memory profile).
- Real-world headroom: the user's actual library exports at 366 KB
(27 notes + one 260 KB attachment) → peak well under 50 MB. Roughly
1000x headroom before the gate.
- Bonus finding: a ~1.6 GB attachment library first dies in **ObjectBox
JVM** (`DbFullException` — objectbox-java caps DB size), not in the
bridge. The phone's objectbox-android has its own ceiling; irrelevant
at current scales.
Verdict: record, don't redesign (plan wording honoured). The streaming
formatVersion=2 idea stays parked for Phase 2 and becomes *required*
iff attachment libraries approach ~25 MB.