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

Avoid useless string releases in arginfo.h files #17344

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

Closed
nielsdos wants to merge 1 commit into php:master from nielsdos:no-useless-rel

Conversation

Copy link
Member

@nielsdos nielsdos commented Jan 3, 2025

These just contribute to code bloat. For the interned strings we don't need to release them and for the non-interned ones we can use the _ex variant to avoid generating the branching code.

Reduces the size of the text section of the CLI binary by 0.166% on a default build.

iluuu1994, Girgias, DanielEScherzer, KsaR99, zeriyoshi, javiereguiluz, ddevsr, and medabkari reacted with thumbs up emoji mvorisek and ddevsr reacted with heart emoji staabm, javiereguiluz, and ddevsr reacted with rocket emoji
These just contribute to code bloat. For the interned strings we don't
need to release them and for the non-interned ones we can use the _ex
variant to avoid generating the branching code.
Reduces the size of the text section of the CLI binary by 0.166% on a
default build.
Copy link
Member

@DanielEScherzer DanielEScherzer left a comment

Choose a reason for hiding this comment

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

I was planning to send a patch to do the same thing in the next few days, don't have approval rights but makes sense to me

Comment on lines 87 to -90
ZVAL_LONG(&const_TARGET_CLASS_value, ZEND_ATTRIBUTE_TARGET_CLASS);
zend_string *const_TARGET_CLASS_name = zend_string_init_interned("TARGET_CLASS", sizeof("TARGET_CLASS") - 1, 1);
zend_declare_typed_class_constant(class_entry, const_TARGET_CLASS_name, &const_TARGET_CLASS_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
zend_string_release(const_TARGET_CLASS_name);
Copy link
Member

@dstogov dstogov Jan 9, 2025

Choose a reason for hiding this comment

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

I would think about specialized functions that accept char* and size_t```. Also may be add specialization by type. Actually, we already have zend_declare_class_constant_long()`` that we used before...
Probably API should be adjusted according to the new requirements.

Copy link
Member Author

Choose a reason for hiding this comment

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

Slightly surprising, the difference is that zend_declare_class_constant_long (and zend_declare_class_constant etc) create a constant whose value is a long but has no type declaration:

return zend_declare_typed_class_constant(ce, name, value, flags, doc_comment, (zend_type) ZEND_TYPE_INIT_NONE(0));

Comment on lines 93 to -96
zend_string *const_TARGET_FUNCTION_name = zend_string_init_interned("TARGET_FUNCTION", sizeof("TARGET_FUNCTION") - 1, 1);
zend_declare_typed_class_constant(class_entry, const_TARGET_FUNCTION_name, &const_TARGET_FUNCTION_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
zend_string_release(const_TARGET_FUNCTION_name);
Copy link
Member

@dstogov dstogov Jan 9, 2025

Choose a reason for hiding this comment

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

I have assumption, that in some edge case zend_string_init_interned() may return a non-interned string.
e.g. when DSO extension is loaded at run-time and opcache is active, or when opcache.interned_strings_buffer is insufficient.
Can you please check this.

Comment on lines 128 to +130
zend_string *property_flags_name = zend_string_init("flags", sizeof("flags") - 1, 1);
zend_declare_typed_property(class_entry, property_flags_name, &property_flags_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
zend_string_release(property_flags_name);
zend_string_release_ex(property_flags_name, 1);
Copy link
Member

@dstogov dstogov Jan 9, 2025

Choose a reason for hiding this comment

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

Why do we use zend_string_init here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was not able to find the reason why. zend_declare_property_string etc also do not use an interned string when it creates the string.
It does get interned here however, but only for persistent modules:

php-src/Zend/zend_API.c

Lines 4626 to 4628 in b8ee4c2

if (is_persistent_class(ce)) {
name = zend_new_interned_string(zend_string_copy(name));
}

Copy link
Member Author

Accidentally messed up the PR id... Sorry

zend_string *property_interval_class_DateInterval = zend_string_init("DateInterval", sizeof("DateInterval")-1, 1);
zend_declare_typed_property(class_entry, property_interval_name, &property_interval_default_value, ZEND_ACC_PUBLIC|ZEND_ACC_VIRTUAL, NULL, (zend_type) ZEND_TYPE_INIT_CLASS(property_interval_class_DateInterval, 0, MAY_BE_NULL));
zend_string_release(property_interval_name);
zend_string_release_ex(property_interval_name, 1);
Copy link
Member

Choose a reason for hiding this comment

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

zend_string_release_ex(zend_string *s, bool persistent)

Shouldn't that 1 therefore be a true ?

Copy link

There has not been any recent activity in this PR. It will automatically be closed in 7 days if no further action is taken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@derickr derickr derickr left review comments

@dstogov dstogov dstogov left review comments

@DanielEScherzer DanielEScherzer DanielEScherzer left review comments

@TimWolla TimWolla TimWolla approved these changes

@kocsismate kocsismate kocsismate approved these changes

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

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

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

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

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

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

@adoy adoy Awaiting requested review from adoy adoy 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 によって変換されたページ (->オリジナル) /