Refactor some ext/pcre code for performance - #12447
Merged
Merged
Conversation
The call overhead of this function is quite large.
This is allocated together with the match data and stays loop invariant: the pointer is always the same (the values not however).
The lookup is loop invariant.
Girgias
approved these changes
Oct 16, 2023
Comment on lines
+1321
to
+1323
| zval tmp; | ||
| ZVAL_NULL(&tmp); | ||
| zend_hash_next_index_insert_new(match_sets[i], &tmp); |
Member
There was a problem hiding this comment.
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.
Member
Author
There was a problem hiding this comment.
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
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
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.
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.