Skip to content

Zero Host GC & Deterministic Latency ​

One of the foundational design choices of RestPHP is the complete elimination of host runtime garbage collection.


The "Double GC" Problem in Go-based Runtimes ​

Modern persistent PHP application servers such as FrankenPHP and RoadRunner are written in Go. While Go provides high concurrency through goroutines, its memory management relies on a concurrent Stop-The-World (STW) Garbage Collector.

When running high-throughput web workloads:

  1. PHP's Cyclic GC: The PHP Zend Engine has its own garbage collector (zend_gc_collect_cycles) to clean up circular references in userland variables.
  2. Go's Host GC: The host server (Go) continuously allocates temporary memory buffers for HTTP headers, TCP buffers, and request routing, triggering periodic Go GC phases.

Impact on p99 Tail Latency ​

During Go GC cycles, CPU cores are diverted to mark-and-sweep phases, and thread scheduling is briefly paused. This causes:

  • GC Jitter: Periodic latency spikes where requests that normally take 2ms suddenly take 15ms or 40ms.
  • Unpredictable p99/p99.9 Latency: Critical in enterprise microservices where SLA guarantees depend on consistent tail latency.

The Rust Advantage: Compile-Time RAII ​

Rust does not have a runtime garbage collector:

  • Deterministic Destruction (RAII): Memory allocated for incoming requests, headers, and responses is freed the exact microsecond the variable falls out of scope.
  • No Background Sweepers: Zero background CPU cycles are spent scanning heap pointers.
  • Tail-latency objective: the Rust host has no garbage collector; p99 behavior still requires reproducible workload-specific benchmarks.

Released under the MIT / Apache-2.0 License. Powered by Rust & Zend Engine.