Repository navigation
ext/standard: Avoid redundant searches in str_replace() - #25851
Open
LamentXU123 wants to merge 2 commits into
Open
LamentXU123 wants to merge 2 commits into
LamentXU123 wants to merge 2 commits into
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
AWS x86_64 (c6id.metal)
Laravel 12.11.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)
Symfony 2.8.0 demo app - 50 iterations, 50 warmups, 100 requests (sec)
Wordpress 6.9 main page - 50 iterations, 20 warmups, 20 requests (sec)
bench.php - 50 iterations, 20 warmups, 2 requests (sec)
|
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.
When the search string is longer than one byte and its replacement has a different length, str_replace() counts matches before allocating the result.
Two things:
Err, so now when the search string occurs once, the copy pass performs no substring searches.
Before this PR the call average use 139.0 ms, after this it use only 96.1 ms roughly 30.86% increasement. Also this can cause some reducsion in memory consumption as well.
I will look at the performance PR later on but not now. Today I spent all my open source time on this stuff. It is really very interesting to do these optimizations :) I am happy to see such improvement on such a critical function.