Extreme-Constraint Node Runtime Tuning (lazy require proxies, V8 heap caps, GC scheduling)

gitingest_pocketclaw_pocketclaw · tools/optimize-ram.sh · shell · MIT
infra, tag:v8-heap-tuning, tag:lazy-require, tag:garbage-collection, tag:memory-cap

37 Proxy-based deferred `require` shims, a capped V8 heap with 2 MB semi-space, `--expose-gc` every 30s, and a scheduled 6h restart to bound a ~2 MB/h leak — running a full agent gateway in ~190 MB RSS. The lazy-proxy require pattern and the honest 'restart to contain the leak' tactic transfer to any memory-pressured Cobalt VPS; the Android-6 hacks do not.

#!/system/bin/sh
# Source: https://github.com/pocketclaw/pocketclaw | License: MIT | Copyright 2026 Robin Monteiro
# Provided via justclaw.it.com; keep this notice with the code.
# PocketClaw RAM optimizer — run from ADB after boot.
# Relaunches gateway outside Termux cgroup, then kills Termux Dalvik processes.
# Uses kill -9 (NOT am force-stop) to preserve BOOT_COMPLETED for next reboot.
#
# Usage: adb shell sh /data/local/tmp/optimize-ram.sh

PREFIX=/data/data/com.termux/files/usr
LOGPFX="[optimize]"

echo "$LOGPFX Starting RAM optimization..."

# Step 1: Kill existing gateway (if running inside Termux cgroup)
OLD_GW=$(ps | grep openclaw-gateway | grep -v grep | awk '{print $2}')
if [ -n "$OLD_GW" ]; then
    echo "$LOGPFX Killing old gateway (PID $OLD_GW, inside Termux cgroup)..."
    #

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key