Skip to content

zip: skip the entry name allocation when there is no add_path - #22975

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:perf/zip-entry-name-no-alloc
Open

zip: skip the entry name allocation when there is no add_path#22975
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:perf/zip-entry-name-no-alloc

Conversation

@iliaal

@iliaal iliaal commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

php_zip_add_file() takes a char*/length pair, so without a prefix to concatenate the entry name was allocated and released once per file only to pass one through. Hand it file_stripped directly, and hold basename until after the call because file_stripped can 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 the expand_filepath() and stat() 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.

@iliaal
iliaal requested a review from LamentXU123 as a code owner July 31, 2026 14:43
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
@LamentXU123

Copy link
Copy Markdown
Member

Seems correct. I will have a closer look later.
This worth an optimization entry in the UPGRADING file IMO

@iliaal
iliaal requested a review from Girgias July 31, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants