Skip to content

Long-running scan memory profiling + leak detection #26

@truthixify

Description

@truthixify

Labels: Stellar Wave, perf, test, drips, help-wanted
Tier: M (2–4 days)
Type: perf / test

Context

The Spectre TEE agent runs for months. Its scanner is the hottest code path. A small memory leak in the SDK becomes an OOM kill in production. We've never run the SDK's scan loop under a profiler to find out.

Scope

  1. Build a long-running harness at test/leak/scan-leak.test.ts:
    • Calls scanAnnouncements (or scanAnnouncementsStream after #09) in a tight loop.
    • Synthetic dataset of 10k announcements; loop runs 10k iterations.
    • Captures heap snapshots at intervals via v8.writeHeapSnapshot (Node) or performance.memory (browser).
  2. Detect leaks: compute slope of RSS over iterations. Fail if slope > N KB per iteration (tunable).
  3. Profile hot paths — run the harness with --prof (V8 profiler) and clinic.js doctor. Capture flame graphs.
  4. Identify and fix any leaks found. Common suspects:
    • Closures holding references to large buffers
    • Event listener accumulation
    • The cache layer (from #17) not evicting properly
    • Worker pool workers not being terminated
  5. Add CI — the leak test runs nightly, fails on regression.

Specific things to check

  • After scanAnnouncements returns, the input announcements array should be garbage-collectible — we shouldn't be holding onto it.
  • After pool.scanAll returns, all worker threads must be terminated.
  • The IndexedDB cache shouldn't grow without bound (it has a 50 MB cap per #17, verify enforcement).

Acceptance criteria

  • Leak detection harness committed.
  • Profiling outputs (flame graph PNG or HTML) committed.
  • Any identified leaks fixed.
  • CI nightly job.
  • Documented "how to interpret the heap snapshot" guide for future debugging.

Why this matters

The TEE's job is privacy. The TEE crashing because the SDK leaks is a privacy failure that looks like a reliability failure. We should know our SDK is leak-clean before a real user notices.

Resources

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programdripsFunded via Drips Networkhelp wantedExtra attention is neededperfPerformance / optimizationtestTest coverage / harness

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions