Skip to content

ext/standard: Various minor optimizations (2026-9) - #23690

Open
LamentXU123 wants to merge 5 commits into
php:masterfrom
LamentXU123:opt-sept
Open

LamentXU123 wants to merge 5 commits into
php:masterfrom
LamentXU123:opt-sept

Conversation

@LamentXU123

Copy link
Copy Markdown
Member

Commits should be reviewed separately. The optimization is mostly using *_new() function for less unnecessary checks.

@devnexen

devnexen commented Sep 15, 2026

Copy link
Copy Markdown
Member

as far as array_chunk optimisation goes, this PR seems to go deeper.

@LamentXU123

Copy link
Copy Markdown
Member Author

Oh I didn't see that PR. I will revert array_chunk optimisation here since that PR seems to cover all my optimizations in this PR.

Integer keys are copied unchanged from the input and remain unique in the
new result. Use zend_hash_index_add_new() to avoid redundant checks.
Parsed fields are appended sequentially to a new array. Use append-new
insertion for the fields and for the single-value blank-line result.
Repeated option values accumulate in private arrays that are only appended
to. New option keys are inserted after a failed lookup. Use known-new
insertion helpers for both cases.
Each call builds a new result with distinct fixed field names. Use
zend_hash_add_new() for these fields.

@iliaal iliaal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, nice to see focus on performance, thanks!

Comment thread ext/standard/file.c Outdated
}

array_init(return_value);
array_init_size(return_value, 26);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: derive this from the table like filestat.c does, 2 * (sizeof(stat_sb_names) / sizeof(*stat_sb_names)), so the two can't drift.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct :) Thanks.

@devnexen

Copy link
Copy Markdown
Member

I did benchmark on my own, seems only *stat() calls demonstrate noticeable positive differences, the rest is within noise. Might be nice to publish yours.

@iliaal

iliaal commented Sep 15, 2026

Copy link
Copy Markdown
Member

I did benchmark on my own, seems only *stat() calls demonstrate noticeable positive differences, the rest is within noise. Might be nice to publish yours.

About the same here, but semantically changes look right to me, so on that basis I think ok for 8.6

@devnexen

Copy link
Copy Markdown
Member

Fair. Anyhow, it is more up to gina here :)

stat(), lstat() and fstat() return 13 integer keys and 13 string keys.
Allocate a mixed table for all 26 entries up front to avoid growing and
converting an intermediate packed array. Use append-new insertion for
the unique numeric keys.
@LamentXU123

Copy link
Copy Markdown
Member Author

Mostly the optimizations are minor so it's hardly observable. IMO this is correct from the C-side and assembly-side. cc @Girgias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants