Repository navigation
ext/standard: Optimize pack() by avoiding redundant padding in pack()… - #24133
Merged
Merged
Conversation
devnexen
reviewed
Oct 5, 2026
| . Improved performance of array_splice() when inserting without removing | ||
| elements. | ||
| . Improved performance of str_rot13(). | ||
| . Improved performance of pack() for string formats (a, A and Z). |
Member
There was a problem hiding this comment.
I just benchmarked it, the win is mainly large strings, it s kind of the same otherwise.
Member
Author
There was a problem hiding this comment.
Yeah it make sense. The improvement should be directly propotional to the length of the string.
devnexen
reviewed
Oct 5, 2026
| (ZSTR_LEN(str) < arg_cp) ? ZSTR_LEN(str) : arg_cp); | ||
| arg_cp = MIN(ZSTR_LEN(str), arg_cp); | ||
| if (arg_cp < arg) { | ||
| memset(&ZSTR_VAL(output)[outputpos + arg_cp], |
Member
There was a problem hiding this comment.
I wonder if the compiler might be able to optimise the case without the guard above. But that s really nitpick of course, definitely not a blocker.
Member
Author
There was a problem hiding this comment.
With gcc -O2
569642: cmp rcx,rdx
569645: jae 5696a3
569647: sub rdx,rcx
; ...
569685: call 201490 <memset@plt>
; ...
5696a3: lea rdi,[r12+r11*1]
5696a7: lea rsi,[r10+0x18]
5696ab: mov rdx,rcx
; ...
5696b8: call 202570 <memcpy@plt>if we remove the if branch:
569654: cmovbe rax,rdx
569658: movsxd rdx,r9d
; ...
569665: sub rdx,rax
; ...
56968c: call 201490 <memset@plt>
; ...
5696a7: call 202570 <memcpy@plt>So in this case it is useful.
devnexen
approved these changes
Oct 5, 2026
Member
Author
|
Thanks! |
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.
… string formats
Fill only the trailling padding instead of filling the whole field. This avoids immediate overwrites and is more effective.