Skip to content

refactor: cgi strings#2188

Merged
AlliBalliBaba merged 39 commits intomainfrom
perf/cgi-strings
Mar 4, 2026
Merged

refactor: cgi strings#2188
AlliBalliBaba merged 39 commits intomainfrom
perf/cgi-strings

Conversation

@AlliBalliBaba
Copy link
Contributor

This PR does a bit of cleanup with how Cgi strings are registered by moving the zend_string keys to a struct on the C side. This also has some performance benefits, mainly by not having to do map access and correctly sizing the $_SERVER array.

Server registration goes from around 5.5% of request time to around 3.5%.

Draft as waiting for #2058 first.

@AlliBalliBaba AlliBalliBaba marked this pull request as ready for review March 1, 2026 22:05
@dunglas dunglas requested a review from Copilot March 2, 2026 17:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors how CGI/$_SERVER string keys are managed by moving hard-coded zend_string keys into a C-side interned-strings struct, reducing Go-side map lookups/allocations and enabling more efficient $_SERVER sizing during registration.

Changes:

  • Introduces C-side interned string registry (frankenphp_strings) and a frankenphp_server_vars struct to bulk-register known $_SERVER variables with pre-sized hashtable capacity.
  • Simplifies Go-side CGI/server-variable registration to rely on C-side known keys, keeping only the common-header cache map in Go.
  • Minor header handling refactor in Go to pass sapi_header_struct directly.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
phpmainthread.go Moves common header zend_string cache to a package-global map and initializes it once.
frankenphp.h Defines frankenphp_server_vars and frankenphp_strings interned-string registry; updates exported APIs.
frankenphp.go Adjusts header parsing helper to accept sapi_header_struct.
frankenphp.c Implements interned-string initialization, server var bulk registration, and updates request variable registration flow.
env.go Captures OS env count for $_SERVER pre-sizing; switches to newPersistentZendString.
cgi.go Reworks known CGI var registration to use C-side interned keys/values; adds tlsProtocol and helper wrappers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@AlliBalliBaba AlliBalliBaba merged commit 356d2e1 into main Mar 4, 2026
93 of 105 checks passed
@AlliBalliBaba AlliBalliBaba deleted the perf/cgi-strings branch March 4, 2026 16:20
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.

3 participants