Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Arginfo: reuse zend_string objects for initializing attribute values #19241

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

Merged

Conversation

Copy link
Member

@DanielEScherzer DanielEScherzer commented Jul 25, 2025

Avoid initializing the same string content multiple times and make use of the fact that the strings created to initialize attribute values are not freed by simply making use of an existing zend_string with the same content if one is available.

mvorisek reacted with thumbs up emoji
Avoid initializing the same string content multiple times and make use of the
fact that the strings created to initialize attribute values are not freed by
simply making use of an existing zend_string with the same content if one is
available.
Copy link
Member Author

The gen_stub code is kind of ugly, but I'm working on cleaning up that file and will continue to do so, it shouldn't block this improvement


This is the third part of my follow-up to #18780 (after #19075 and #19141) dealing with reducing the work of registering attributes on constants (and other things)


the same strings are allocated twice

It should probably be safe to just intern them all. They are always allocated on start-up, so the memory will be used either way. Interning should just reduce it, no?

Yes I agree.
If you pinky promise that you're gonna look at it before 8.5's release I'll allow it.

Originally posted by @nielsdos in #18780 (comment)

Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a bit of messiness / code churn in the gen_stub file. Conceptually this looks good though. Leaving the final review for @kocsismate
Thinking about the interning suggestion: it's probably better to not intern these but keep it as-is, otherwise we will also take up shm which is kinda pointless.

"attribute_{$escapedAttributeName}_{$nameSuffix}_arg{$i}_str"
);
if ($arg->value instanceof Node\Scalar\String_) {
$declaredStrings[$arg->value->value] = "attribute_{$escapedAttributeName}_{$nameSuffix}_arg{$i}_str";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this string that you construct (i.e. the variable name) should be split out to a separate variable, as you already construct it previously on line 3361 too.

Copy link
Member Author

@DanielEScherzer DanielEScherzer Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"this string" being "attribute_{$escapedAttributeName}_{$nameSuffix}_arg{$i}_str" ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Member Author

@DanielEScherzer DanielEScherzer Jul 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the other instance where the variable is declared is just 3 lines earlier, I don't think a variable is needed

Copy link
Member Author

There's a bit of messiness / code churn in the gen_stub file

Yeah, its pretty messy, if you look in the history of that file though I've been working to clean it up and given how few people probably look at that file I think the messiness is acceptable

nielsdos reacted with thumbs up emoji

Copy link
Member

sure

Copy link
Member

@kocsismate kocsismate left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DanielEScherzer DanielEScherzer merged commit ff810d5 into php:master Jul 28, 2025
9 checks passed
@DanielEScherzer DanielEScherzer deleted the arginfo-reuse-attrib-strings branch July 28, 2025 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@nielsdos nielsdos nielsdos left review comments

@kocsismate kocsismate kocsismate approved these changes

@bukka bukka Awaiting requested review from bukka bukka is a code owner

@kamil-tekiela kamil-tekiela Awaiting requested review from kamil-tekiela kamil-tekiela is a code owner

@derickr derickr Awaiting requested review from derickr derickr is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /