[PHP] Optimized away hex2bin() call in generated code#8006
Merged
haberman merged 6 commits intoprotocolbuffers:masterfrom Nov 5, 2020
Merged
[PHP] Optimized away hex2bin() call in generated code#8006haberman merged 6 commits intoprotocolbuffers:masterfrom
haberman merged 6 commits intoprotocolbuffers:masterfrom
Conversation
…ng hex2bin() at runtime.
1. Eliminate hex2bin() call by putting binary data directly into PHP strings. 2. upb optimizations, including a new hash function.
gerben-s
approved these changes
Nov 5, 2020
copybara-service bot
pushed a commit
that referenced
this pull request
Jan 24, 2024
Follow up on #10404, the initial description: > For the sake of performance, the hex2bin call was removed from the generated PHP code in #8006 However, after this PR all autogenerated files contain binary data, which makes it hard or even impossible to see using common tools (git and github included (i.e. [this file](https://github.com/protocolbuffers/protobuf/blob/main/php/src/GPBMetadata/Google/Protobuf/Struct.php)), as well as some code editors) since most software considers such files as binary ones and not as code. Alexander suggested using a hex representation of string literals and I updated the original patch a bit, not hex-encoding printable characters. Benchmarks from [#10404#issuecomment-1635939062](#10404 (comment)) ``` The percent of printable chars: 0.83869 (80112 vs 15408) hex parsing: 3.22371, length=382090 hex2Bin parsing: 1.18489, length=191059 hexAscii parsing: 0.89524, length=142306 (suggested option) binary parsing: 0.26437, length=95542 ``` Closes #13911 COPYBARA_INTEGRATE_REVIEW=#13911 from mikhainin:do_not_store_binary_data_inside_php_files 490958e PiperOrigin-RevId: 601123255
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.
Generated code now embeds the binary descriptor directly instead of embedding hex and calling hex2bin().
This saves a small amount of CPU when importing PHP types.