Skip to content

[Performance] Expose TinyGo GC Options and Support Explicit sweeps #5

@HaHiepThanh

Description

@HaHiepThanh

📋 Context & Problem Description

Recent Playwright resource benchmarks reveal that while Gutter TinyGo builds are highly optimized for bundle size (407 KB gzip vs Go std's 1.8 MB gzip), they consume significantly more memory than Go std at scale.
At 10,000 items, TinyGo's heap expands to 48 MB (52.6 MB total RAM), compared to Go std's 36 MB heap (40.1 MB total RAM).

This is due to LLVM/TinyGo's conservative GC implementation, which defers sweep cycles to reduce footprint and size, causing memory accumulation when allocating thousands of element structs during hydration.

💡 Proposed Solution & Implementation Plan

  1. TinyGo GC Selector in CLI:
    Allow selecting the garbage collector algorithm in gutter build and gutter run:
    • --gc=conservative (default)
    • --gc=leaking (useful for high-speed, short-lived tasks where memory recovery is not required)
  2. Explicit GC Triggers:
    Provide a helper to trigger an explicit GC sweep on the client (e.g. right after hydration completes or route transition finishes) to release unneeded structs:
    // Internally wraps runtime.GC() on WASM target
    gutter.TriggerGC()

🎯 Impact & Benefits

  • Better RAM Management: Prevents memory ballooning on large-scale pages using Gutter with TinyGo.
  • Flexible Builds: Empowers developers to choose the right GC strategies for their workloads.

🏷️ Suggested Labels

performance, cli, wasm

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    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