Skip to content

feat(rust): expose Run::heap_bytes without the gc-stats feature - #175

Merged
kommander merged 7 commits into
devfrom
heap-size
Dec 2, 2026
Merged

kommander merged 7 commits into
devfrom
heap-size

Conversation

@simonklee

@simonklee simonklee commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

What

  • Add Run::heap_bytes(&self) -> Option<u64>. It is always available (no gc-stats feature) and is backed by an Arc<AtomicU64> on Run.
  • Publish every Vm::heap_measure result to it, in the shared size model of heap.rs, including the measurement of an over-limit stop.
  • Measure once on a run's first wait for the host when max_heap_bytes is set and nothing has been measured yet (Vm::heap_wait). A long-lived idle run then reports its reachable bytes, and later waits pay for no measurement.
  • Document it in rust/README.md under "Only Rust has".

Why

The OpenCode Rust client reports the live heap of an idle plugin in production builds. Today that number needs the benchmark-only gc-stats feature.

Upstream

Rebased cleanly onto origin/dev (dec90d1; tip 3346c0d, 0 conflicts). Nothing was superseded by merged upstream work.

Compared with open PRs:

Tests

  • Added run_heap_bytes_reports_last_measured_reachable_bytes_without_gc_stats in rust/crates/psychoscript/tests/heap.rs: None without max_heap_bytes, the first-wait measurement of an idle run, an update on growth past the pacing threshold, the exact 16,064 bytes of the shared size model, and the value recorded by an over-limit stop.
  • cargo fmt --all --check, cargo clippy --locked --workspace --all-targets -- -D warnings, cargo clippy --locked -p psychoscript --no-default-features --all-targets -- -D warnings, cargo test --locked -p psychoscript (including tests/heap.rs 12/12; two timing-sensitive tests/clock.rs tests flaked under tux's nice -n 19 / CPUQuota=400% load; tests/hostile.rs passed on rerun), and cargo test --locked -p psychoscript --no-default-features --test locale_fallback --test heap pass.

Review changes: merged dev; added Runtime::measure_heap(true), which reuses the heap meter without a limit and measures at waits for the host once the run has allocated 1/16 of its last measurement; a limit keeps dev's schedule, so it no longer adds the first-wait measurement; UNMEASURED no longer takes Run's doc comment; the tests check bounds instead of 16,064 and cover round-trip mode and a mid-run suspend/resume; lazy built-ins are recorded with or without a meter, so a state saved without the opt-in measures the same once resumed with it; README updated, including that the reading can lag after a big drop.

@simonklee
simonklee requested a review from kommander December 2, 2026 12:37
Attach Run's doc comment to Run again, assert heap_bytes by its bounds instead of an exact size, and say in the README
that it measures only with max_heap_bytes.
…ut a heap limit

The heap meter now runs with a limit, with measure_heap, or both: a limit keeps its own schedule and check, and
measure_heap measures at the run's waits for the host once it allocated a sixteenth of what it last reached. A
limit alone no longer measures at the first wait.
# Conflicts:
#	rust/crates/psychoscript/src/runtime.rs
…at resumes with one

A state saved without measure_heap or a limit and resumed with measure_heap counted the lazy groups set up before
the suspend as program bytes.
@kommander kommander closed this Dec 2, 2026
@kommander kommander reopened this Dec 2, 2026
@kommander
kommander merged commit 42eebbd into dev Dec 2, 2026
2 checks passed
@kommander
kommander deleted the heap-size branch December 2, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants