UPSTREAM PR #27013: Add php_64_bit_only codegen option to the PHP generator#153
UPSTREAM PR #27013: Add php_64_bit_only codegen option to the PHP generator#153loci-dev wants to merge 1 commit into
Conversation
OverviewAnalysis of 10,156 functions in Function counts: 41 modified, 0 new, 0 removed, 10,115 unchanged Function AnalysisMost Significant Changes:
Other analyzed functions show sub-microsecond changes from security hardening (stack canary validation) or compiler optimizations. Flame Graph ComparisonFunction: Base version: Target version: Target introduces zero-argument template instantiation dominated by logging infrastructure (SendToLog 3.85ms, Flush 3.92ms, LogMessage 1.03ms), measuring error/diagnostic path rather than normal code generation. 💬 Questions? Tag @loci-dev |
6014f4a to
8b66a5e
Compare
Generated PHP code currently type-hints 64-bit integer fields as
`int|string` to cover 32-bit PHP builds, where values that overflow a
native `int` are returned as strings. On 64-bit PHP — the mainstream
deployment — the runtime always returns native `int`, so the union is
dead weight that noisies up static analysis, IDE autocompletion, and
docs for everyone who has committed to 64-bit.
This change adds an opt-in CLI option, analogous to `aggregate_metadata`:
protoc --php_out=assume_64_bit_php:. foo.proto
When the flag is present, INT64/UINT64/SINT64/FIXED64/SFIXED64 fields
emit `int` instead of `int|string` across setter signatures, PHPDoc
`@param` / `@return` / `@type`, and `RepeatedField<...>` generics
(which naturally collapse from `RepeatedField<int>|RepeatedField<string>`
to `RepeatedField<int>`). Wrapper types (`Int64Value`, `UInt64Value`)
honor the flag via `Options` threaded into the wrapper doc-comment
helpers. Default behavior (flag absent) is unchanged.
Scope:
- Codegen only. Runtime libraries (GPBUtil.php, convert.c) already
return native `int` on 64-bit PHP regardless of this flag.
- No change to checked-in generated WKT .php files; they remain on
default behavior unless regenerated with the flag.
- No new .proto file-level option.
- Descriptor-mode generation (`is_descriptor=true`) is intentionally
unchanged.
Unit tests cover the flag-on and flag-absent paths, scalar and repeated
64-bit fields, and verify the `int|string` union is fully absent when
the flag is enabled.
fd419f5 to
d64617d
Compare
OverviewAnalysis of 10,162 functions across build.protoc-stable shows 11 modified functions (0.11%) with minor performance improvements. Power consumption decreased by 0.044% (589,046 nJ → 588,788 nJ). Changes introduce Function AnalysisPhpDocSetterTypeName (most impacted):
GenerateAll (entry point):
GenerateFieldAccessor:
ConstantNamePrefix and GeneratedMetadataFileName: Minor improvements (-0.56% to -2.89% throughput) from compiler optimizations with no source code changes. All modified functions are in the PHP code generator (compile-time), not runtime hot paths. Improvements affect protoc build times, not generated code performance. Changes demonstrate good engineering: adding functionality with minimal overhead while achieving performance gains through API cleanup. 💬 Questions? Tag @loci-dev |
ec8c960 to
e3c8630
Compare
f292971 to
1fdfb93
Compare


Note
Source pull request: protocolbuffers/protobuf#27013
Generated PHP code currently type-hints 64-bit integer fields as
int|stringto cover 32-bit PHP builds, where values that overflow a nativeintare returned as strings. On 64-bit PHP — the mainstream deployment — the runtime always returns nativeint, so the union is dead weight that noisies up static analysis, IDE autocompletion, and docs for everyone who has committed to 64-bit.This change adds an opt-in CLI option, analogous to
aggregate_metadata:When the flag is on, INT64/UINT64/SINT64/FIXED64/SFIXED64 fields emit
intinstead ofint|stringacross setter signatures, PHPDoc@param/@return/@type, andRepeatedField<...>generics (which naturally collapse fromRepeatedField<int>|RepeatedField<string>toRepeatedField<int>). Wrapper types (Int64Value,UInt64Value) honor the flag viaOptionsthreaded into the wrapper doc-comment helpers. Default behavior (flag absent or=false) is unchanged.Scope:
inton 64-bit PHP regardless of this flag.is_descriptor=true) is intentionally unchanged.Unit tests cover flag on/off/absent/invalid paths, scalar and repeated 64-bit fields, and verify the
int|stringunion is fully absent when the flag is enabled.