Skip to content

Refactor some ext/pcre code for performance - #12447

Merged
ndossche merged 11 commits into
php:masterfrom
ndossche:pcre-stuff
Oct 16, 2023
Merged

Refactor some ext/pcre code for performance#12447
ndossche merged 11 commits into
php:masterfrom
ndossche:pcre-stuff

Conversation

@ndossche

Copy link
Copy Markdown
Member

Gives about a 1.1-1.2% performance win on Symfony demo.
Spit over various commits with short reasoning. Once merged, can be squashed into one with the commit descriptions and titles in a single commit.

@Girgias Girgias 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.

LGTM

Comment thread ext/pcre/php_pcre.c Outdated
Comment thread ext/pcre/php_pcre.c
Comment on lines +1321 to +1323
zval tmp;
ZVAL_NULL(&tmp);
zend_hash_next_index_insert_new(match_sets[i], &tmp);

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.

We really should add zend_hash APIs to deal with those cases.
We have add_index_*() and add_assoc_*() when the array is wrapped in a zval but nothing when working with a HashTable directly.

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.

Probably, but it's worth checking first if this occurs often before adding more public APIs. I don't know off the top of my head how common this is.
In any case, I'm not gonna deal with it in this PR :p

Comment thread ext/pcre/php_pcre.c Outdated
Comment thread ext/pcre/php_pcre.c Outdated
@ndossche
ndossche merged commit 1e2e2f3 into php:master Oct 16, 2023
adrian-enspired pushed a commit to adrian-enspired/php-src that referenced this pull request Aug 4, 2026
* Always inline populate_match_value and fix argument type

The call overhead of this function is quite large.

* Use _new variant of zend_hash in some places to avoid additional check

* Move allocation of match_sets down to simplify and reduce code size

* Move pcre2_get_ovector_pointer out of the loop

This is allocated together with the match data and stays loop invariant:
the pointer is always the same (the values not however).

* Mark error condition as cold block

* Simplify condition: subpats is already checked

* Move array size preallocation to use allocate the up-to-date size

* Simplify condition

* Rework internal functions to avoid repeated unwrapping

* Remember Z_ARRVAL_P(return_value)

The lookup is loop invariant.

* Mark some pointers as const
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.

2 participants