0xMiden / 0xMiden/web-sdk

Long browser session retains ~1.2 GB ArrayBuffer with retainer chain ending at Dexie — how should the SDK lifecycle handle this?

未关闭
#160 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
TypeScript
星标
1
派生
21
平均合并
12 小时 14 分钟
30 天内合并 PR
41

描述

Hi — we use `@miden-sdk/miden-sdk` in a browser app for read-only registry queries against the Miden testnet. We've observed a memory pattern in a long-running browser session that we don't fully understand, and we'd appreciate your help interpreting it before we go too far chasing a fix on our side.

### What we observed

A Chrome heap snapshot showed:

- **A single `JSArrayBufferData` system entry of 1,206,714 KB (~1.2 GB)**, accounting for 93% of the page's total memory.
- The Retainers panel traced the keep-alive chain ending at `` in the page's Window.

We did not capture the full retainer path from leaf to root, so we don't yet know whether Dexie is holding the raw bytes (e.g. a cached account-state blob written to IndexedDB) or whether it's incidentally retaining a `WebClient` that owns a `WebAssembly.Memory` instance via Rust glue.

### What we know about our setup

- SDK version: `@miden-sdk/miden-sdk@0.14.9` (pinned; the `0.14.10` patch bump is dependency-only and we expect the same behaviour).
- Import path: default subpath (resolves to `dist/st/eager.js`), not the `/mt` path.
- Browser: Chrome stable on macOS in this report; we've had unconfirmed echoes from iOS Safari + Android Chrome.
- Usage pattern at the time of the snapshot: SDK was auto-connecting on every app boot (we've since changed this — see "What we've already shipped" below). Long session with multiple page visits, each triggering `accounts.getOrImport(accountId)` on one of 4 sharded registry accounts. No on-client proving; reads only.

### What we don't know (and where we'd love your help)

1. **What's the typical retainer story when a `JSArrayBufferData` is held by Dexie in a Miden SDK app?** Is this likely (a) account state / MMR proof bytes that the SDK writes to IndexedDB, kept in JS memory by Dexie's bookkeeping, or (b) the WASM linear-memory backing buffer that's incidentally reachable via a Dexie reference to the WebClient, or (c) something we haven't considered?

2. **Is there a documented lifecycle pattern for the WebClient?** We haven't found a `dispose()` / `destroy()` API and weren't sure if there's a recommended teardown recipe (e.g. drop all references + wait for GC). [PR #1842](https://github.com/0xMiden/miden-client/pull/1842) suggested that aggressive teardown was a bug source historically — is there a stable middle ground?

3. **Are 1+ GB heap sizes considered expected for long-running browser sessions** with the current SDK design, or is this a "we should look into it" symptom on your side too?

4. **If we should debug further on our side**, what would be most useful to capture? A full retainer chain in DevTools? A `client.getSync()` state dump? Both?

We're not asking for a fix — we're asking for help understanding whether what we're seeing is expected behaviour we should design around, or a real issue worth tracking.

贡献指南

打开贡献指南

调研方向

The issue involves memory retention in the Miden SDK, likely in the WebClient or Dexie integration. Start by examining the SDK's IndexedDB usage in the browser, particularly around account state caching. Use Chrome DevTools to capture a full heap snapshot retainer chain from the large ArrayBuffer to the Dexie symbol. Look for lifecycle methods or teardown patterns in the WebClient class to understand proper cleanup.

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, typescript, wasm
领域
backend-api-design, performance
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。