zip: skip the entry name allocation when there is no add_path - #22975
Open
iliaal wants to merge 1 commit into
Open
zip: skip the entry name allocation when there is no add_path#22975iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
php_zip_add_file() takes a char*/size_t pair, so without a prefix to concatenate the zend_string was allocated and released once per entry only to pass one through. Pass file_stripped directly, and hold basename until after the call because file_stripped can point into it. Closes phpGH-22975
iliaal
force-pushed
the
perf/zip-entry-name-no-alloc
branch
from
July 31, 2026 14:44
8adcb24 to
9b362a3
Compare
Member
|
Seems correct. I will have a closer look later. |
LamentXU123
approved these changes
Aug 1, 2026
LamentXU123
left a comment
Member
There was a problem hiding this comment.
Indeed, very good spot. LGTM!
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.
php_zip_add_file()takes achar*/length pair, so without a prefix to concatenate the entry name was allocated and released once per file only to pass one through. Hand itfile_strippeddirectly, and holdbasenameuntil after the call becausefile_strippedcan point into it.Measured on 4000 files with
addGlob(): 22.2/22.2/22.8 ms patched against 23.8/22.2/22.1 ms before, so the saving is under the noise of theexpand_filepath()andstat()the loop already does per entry. This is about the redundant work, not about a number.Same function as #22973, which is the correctness fix; this one only removes the allocation.