php / php/php-src

A way to stop GC wasting CPU time on long-lived objects (GC generations or something else)

Open
#17,131 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Category: GC Feature Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

PHP's GC is currently unsuited to long-running applications because of the lack of GC generations.

Any application which has long-lived objects with many descendents (such as PocketMine-MP's Server) will currently experience significant performance hits from GC runs due to the expense of repeatedly scanning complex dependencies of these objects.

I haven't dived deep into this problem, but I did verify that just the Server alone winding up in the GC root buffer in PocketMine-MP (which it should never do, being an object that stays alive for almost the entire process) costs 1.7 ms of GC time on a 12700k. An average GC run in PM during normal operation costs somewhere in the ballpark of 15ms, despite creating almost zero cycles.

This is a massive performance impact to PM on account of its update cycle taking place every 50 ms, so a 15ms GC pause is serious business.

Runtimes like .NET and Java have GC generations to avoid this problem, which avoid frequently scanning complex long-lived objects.

I understand that the benefit to PHP is relatively small, given that the primary use case is to serve short-lived web requests, but implementing generations in GC would positively affect performance of long-lived applications.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked PocketMine-MP src/Server.php example to understand the long-lived object graph and the reported GC cost. Then locate PHP's GC implementation and relevant tests, reproduce the repeated scanning described here, and define done as a tested approach that reduces work for long-lived objects while preserving cycle collection.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.