-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Fix GH-11507: String concatenation performance regression in 8.3 #11508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When the code was moved to solve the uaf for memory overflow, this caused the refcount to be higher than one in some self-concatenation scenarios. This in turn causes quadratic time performance problems when these concatenations happen in a loop.
I just hope the nullifying won't cause the benchmarks to slow down... At least we know the root cause now so that's a start. |
Used to build with this patch but it does not fix
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks correct, thanks for fixing this!
/* Free result after zend_string_extend(), as it may throw an out-of-memory error. If we | ||
* free it before we would leave the released variable on the stack with shutdown trying | ||
* to free it again. */ | ||
/* Extend first to drop the refcount, such that $x .= ...; may happen in-place. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Release/free first, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes of course 🤦 clearly not awake anymore :p
@andypost Sure? It did for me. |
I was wrong, somehow patch is not applied, rebuilding |
yes, it works, thank you! |
@iluuu1994 Although this might be correct, this worsens the benchmark results. It probably makes sense to find a more optimal way to fix this. |
@nielsdos How big was the difference? Was it a timed benchmark or instruction count? |
Instruction count. Actually, never mind... It was not this PR that caused this. It was an earlier commit today that caused the slowdown (see https://github.com/php/php-src/actions/runs/5343735245/jobs/9687223322) in particular WordPress is now 128427072 instead of 124665438 |
Current PR reports 128432662 https://github.com/php/php-src/actions/runs/5349418998/jobs/9700608975?pr=11508#step:10:38 but 2 weeks ago it was 124643600 - 4M ops added |
Yeah, the root cause is this commit I think: 466fc78. Starting from the merge from that to master it slowed down with 4M ops. |
This is probably caused by the allocation in the else case 🙁 We'll need to revert that and solve it some other way. We can use separate caches for JIT and non-JIT. That should avoid it. |
I reverted this commit for now. I'll try a different solution tomorrow. |
Or have an extra field in |
@nielsdos Good idea, we'll have to postpone to 8.3 due to the ABI break then. But that's fine, I don't want to risk another issue. |
Thank you! As I see "4M ops" are fixed in latest HEAD https://github.com/php/php-src/actions/runs/5350588341/jobs/9703387273#step:10:38 |
When the code was moved to solve the uaf for memory overflow, this caused the refcount to be higher than one in some self-concatenation scenarios. This in turn causes quadratic time performance problems when these concatenations happen in a loop.