regex pod fixes related to /p as it stands today - #24554
Open
demerphq wants to merge 1 commit into
Open
Conversation
This documentation patch updates the docs to explain when and where /p is still relevent, and documents the performance reasons why. For a long time the docs have been incorrectly stating /p is not used or relevant anymore and that COW has made it redundant. This is unfortunately not the case, and it is still relevant for /g matches where the target string is not copied. Its a weird edge case, I bet no-one cares or actually needs it, but because of the flaws in our COW model we would make some code quadratic out of the box by making scalar /g matches copy the target string. As such we need an escape hatch for when the user wants to override that for some reason. I am inclined to think that removing PL_saw_ampersand was premature as well, COW isnt a complete solution for the performance issues that PL_saw_ampersand was solving.
Contributor
| They do not simply rely on copy-on-write for that, since copy-on-write | ||
| sharing is bounded and some target strings cannot use it. Use C</p> if | ||
| you need C<${^PREMATCH}>, C<${^MATCH}>, or C<${^POSTMATCH}> after such a | ||
| match. |
Contributor
There was a problem hiding this comment.
I found "such" confusing. I think this means that if you need any one of the variables, add /p, but it kind of sounded like, "if you have bad experience, add /p"
Contributor
|
This is also related to #24147. |
book
approved these changes
Jul 15, 2026
book
left a comment
Contributor
There was a problem hiding this comment.
Looks good to me. Nice to learn about the limitations of copy-on-write.
Contributor
|
@Leont: Since this is just a doc patch, why not ship it with 5.44? |
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.
This documentation patch updates the docs to explain when and where /p is still relevent, and documents the performance reasons why. For a long time the docs have been incorrectly stating /p is not used or relevant anymore and that COW has made it redundant. This is unfortunately not the case, and it is still relevant for /g matches where the target string is not copied. Its a weird edge case, I bet no-one cares or actually needs it, but because of the flaws in our COW model we would make some code quadratic out of the box by making scalar /g matches copy the target string. As such we need an escape hatch for when the user wants to override that for some reason.
I am inclined to think that removing PL_saw_ampersand was premature as well, COW isnt a complete solution for the performance issues that PL_saw_ampersand was solving.