Repository navigation
perf: assemble cookies directly in the C buffer - #2797
Open
andreybolonin wants to merge 1 commit into
Open
andreybolonin wants to merge 1 commit into
andreybolonin wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reading multiple Cookie fields currently joins them into a Go string, removes NUL bytes into another string when necessary, and copies the result into a C string for PHP.
Compute the filtered length and copy the fields and
;separators directly into the final NUL-terminated C buffer. Preserve empty-field handling, nil versus a non-nil empty result after NUL removal, field order, and the existing joined-length overflow checks. The buffer still uses malloc/free and is released byfrankenphp_free_request_context().Add cookie parsing regression cases for classic and worker mode: absent and empty fields, NUL-only fields, NUL within values, separators around empty fields, duplicates, and long values.
Initial standalone prototype measurements (Go 1.27.3, Apple M2, darwin/arm64, one 150ms sample per case, including freeing the result):
These exploratory results describe the prototype before the joined-length overflow guards were restored; the final revision has not been benchmarked. Go benchmem excludes C allocations. Both implementations request the same final C allocation size, and this change removes intermediate Go strings. Whole-request latency and process RSS were not measured.
Validation:
gofmtandgit diff --checkpassed. The exact final CGO helper passed edge cases and-racein an isolated harness. Differential fuzzing against the previous Join/ReplaceAll behavior passed 580,435 executions;go vetpassed. The added PHP integration cases and full suite require CI: the local environment lacks the required PHP ZTS/shared-library and watcher setup. Benchmarks were not rerun for this PR.