Refactor memory checker to use go-postgres/memcheck #6

Open
opened 2026-08-07 14:22:29 +00:00 by hum3 · 0 comments
Owner

Context

The go-postgres library now has a reusable memcheck package that provides:

  • memcheck.Stats — snapshot of Alloc, TotalAlloc, Sys, HeapObjects, NumGC, Goroutines
  • memcheck.ReadStats() — wraps runtime.ReadMemStats
  • memcheck.FormatBytes() — human-readable byte formatting
  • memcheck.Monitor — configurable memory limit with thread-safe exceeded flag
  • WASM build tag (js && wasm) that calls debug.SetMemoryLimit(900MB) in init()

See: https://codeberg.org/hum3/go-postgres/issues/6

What to change

  1. demo_state.go:checkMemory — Replace with memcheck.Monitor.Check()
  2. capSlice helper — May no longer be needed if memory monitoring is centralised
  3. main_wasm.go:debug.SetMemoryLimit — Remove; the memcheck package init() handles this automatically when imported
  4. Import github.com/drummonds/go-postgres/memcheck instead of direct runtime calls

Benefits

  • Single source of truth for memory limits and monitoring
  • Consistent behaviour between gobank and go-postgres soak tests
  • Less duplicated code

Migrated from Codeberg: originally #6, opened 2026-03-20.

## Context The `go-postgres` library now has a reusable `memcheck` package that provides: - `memcheck.Stats` — snapshot of Alloc, TotalAlloc, Sys, HeapObjects, NumGC, Goroutines - `memcheck.ReadStats()` — wraps `runtime.ReadMemStats` - `memcheck.FormatBytes()` — human-readable byte formatting - `memcheck.Monitor` — configurable memory limit with thread-safe exceeded flag - WASM build tag (`js && wasm`) that calls `debug.SetMemoryLimit(900MB)` in init() See: https://codeberg.org/hum3/go-postgres/issues/6 ## What to change 1. **`demo_state.go:checkMemory`** — Replace with `memcheck.Monitor.Check()` 2. **`capSlice` helper** — May no longer be needed if memory monitoring is centralised 3. **`main_wasm.go:debug.SetMemoryLimit`** — Remove; the `memcheck` package init() handles this automatically when imported 4. Import `github.com/drummonds/go-postgres/memcheck` instead of direct `runtime` calls ## Benefits - Single source of truth for memory limits and monitoring - Consistent behaviour between gobank and go-postgres soak tests - Less duplicated code --- *Migrated from Codeberg: originally [#6](https://codeberg.org/hum3/gobank/issues/6), opened 2026-03-20.*
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
hum3/gobank#6
No description provided.