diff options
| author | Adam Soltys <[email protected]> | 2026-11-06 21:59:36 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-11-06 21:59:36 -0700 |
| commit | 9886d4f1f51a6f0671d68ac3ba115e02b27ed474 (patch) | |
| tree | 6c516be871b4346dfb0210febfd335b5abf46c1a /tools/ark-store-test.js | |
| parent | 31c4598795932b62f5cb5a7e69088561caacb7bf (diff) | |
| download | coinosv3-9886d4f1f51a6f0671d68ac3ba115e02b27ed474.tar.gz coinosv3-9886d4f1f51a6f0671d68ac3ba115e02b27ed474.zip | |
The wallet paints its balance without deep-copying the whole ark state five to seven times on every launch. "Its so slow to load … I'm using the apk. Compared to Minibits or something its way slower" (a user, 2026-11-05): profiled on Adam's Pixel 9 over DevTools, a launch kept the main thread pegged for ~1.7 s, and 1.4 s of it was loadArkState — every arkStateNow() during the first render (balance, history, notices, the Spending figures) structured-cloned the stored state, ~1 MB on a wallet with deep coins, ~220 ms per copy, before the manager connected and its live state took over. ArkStore.peek() hands back the stored object itself (before the store opens, or on localStorage, the parse is kept until the key is next written); wallet.peekArkState() is loadArkState through it, with the misfiled-state repair still going through loadArkState and each object's owner decoded once; arkStateNow and arkWanted read through it — read-only, as they already were with the live ark.state. Same boot on the phone, live tab with the local build: main-thread busy over the first 4 s 3.7 s → 1.8 s, no pegged stretch. tools/ark-store-test.js: peek returns the same object, sees writes at once, and drops a kept localStorage parse on write
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'tools/ark-store-test.js')
| -rw-r--r-- | tools/ark-store-test.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/ark-store-test.js b/tools/ark-store-test.js index 4e02fa0..a72ad81 100644 --- a/tools/ark-store-test.js +++ b/tools/ark-store-test.js @@ -87,4 +87,25 @@ assert.equal(broken.lsMode, true, 'a refusing IndexedDB drops to localStorage'); assert.equal(broken.get(K)._rev, 1); console.log('✓ localStorage fallback'); +// ---- peek: the stored object, no copy; a write is seen at once ---- +const ls4 = new Storage(); +ls4.setItem(K, JSON.stringify({ _rev: 3, vtxos: [] })); +const pk = new ArkStore({ backend: memoryBackend(), ls: () => ls4 }); +const before = pk.peek(K); +assert.equal(before._rev, 3, 'before opening, peek reads localStorage'); +assert.equal(pk.peek(K), before, 'and keeps the parse'); +await pk.open(); +assert.equal(pk.peek(K), pk.peek(K), 'opened: the same object every time'); +assert.notEqual(pk.get(K), pk.peek(K), 'get still copies'); +pk.set(K, { _rev: 4, vtxos: [] }); +assert.equal(pk.peek(K)._rev, 4, 'a write shows in the next peek'); +pk.remove(K); +assert.equal(pk.peek(K), null); +const pl = new ArkStore({ backend: null, ls: () => ls4 }); +pl.set(K, { _rev: 5, vtxos: [] }); +assert.equal(pl.peek(K)._rev, 5); +pl.set(K, { _rev: 6, vtxos: [] }); +assert.equal(pl.peek(K)._rev, 6, 'localStorage mode: a write drops the kept parse'); +console.log('✓ peek reads without copying'); + console.log('\n✅ ark store behaves'); |
