Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix OPcache class preload requirement #13986

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
merged 1 commit into from
Jan 14, 2021
Merged

Fix OPcache class preload requirement #13986

merged 1 commit into from
Jan 14, 2021

Conversation

ITernovtsii
Copy link
Contributor

container.dumper.inline_factories
As stated by @nicolas-grekas in symfony/symfony#32581 (comment)

With preloading, a single big file can, in theory, be similarly fast or faster.

container.dumper.inline_class_loader
With this parameter set to true, we'll do extra include_once for classes already preloaded by OPcache.
Additionally, it can lead to warnings (cannot redeclare class) in classes that use class_alias, like https://github.com/FriendsOfSymfony/FOSHttpCacheBundle/blob/master/src/EventListener/InvalidationListener.php#L33
It's because this class already declared in preload, and PHP tries to declare it again after include_once in service getter.

@nicolas-grekas
Copy link
Member

I don't remember exactly how these settings relate to opcache and I'm afk. If either true or false work, it means we should remove the sentence actually, since these wouldn't be requirements. Please try and confirm what you observe.

@ITernovtsii
Copy link
Contributor Author

ITernovtsii commented Jul 21, 2020

If either true or false work, it means we should remove the sentence actually, since these wouldn't be requirements.

inline_factories: true will work fine with preload, just a bit slower (I guess). So, this can be safely removed or updated to specify that it's a recommendation, not a requirement.

inline_class_loader: true doesn't make sense with preloading in place (except use-case when all services tagged by container.no_preload, which is not in v4.4 anyway). So, we should keep this as a requirement for opcache preload.

@nicolas-grekas
Copy link
Member

Honestly, these claims should be verified before we commit anything.

@MatTheCat
Copy link
Contributor

I checked the four combinations using blackfire on a new Symfony project with preloading enabled and it worked for all of them, so I’m not sure there is any requirement.

Also even if each combination performed roughly the same, container.dumper.inline_factories seemed to bring some benefits.

@ITernovtsii
Copy link
Contributor Author

ITernovtsii commented Nov 24, 2020

@MatTheCat Did you spot cannot redeclare class error with inline_class_loader: true and OPcache preload enabled?

And even if not, it doesn't make sense to call include_once in service getter, as class already preloaded by OPcache and it makes it less efficient.

@MatTheCat
Copy link
Contributor

Did you spot cannot redeclare class error with inline_class_loader: true and OPcache preload enabled?

Nope.

If I refer to https://bugs.php.net/bug.php?id=78169 it should not cause any error, but it is true preloaded classes files will still be included.

@nicolas-grekas the PHP issue seems stalled; did you hear about it elsewhere?

performance.rst Outdated
@@ -111,7 +111,7 @@ performance significantly.
During container compilation, Symfony generates the file with the list of
classes to preload. The only requirement is that you need to set both
``container.dumper.inline_factories`` and ``container.dumper.inline_class_loader``
parameters to ``true``.
parameters to ``false``.
Copy link
Member

Choose a reason for hiding this comment

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

Can't we remove the sentence altogether? To me, the preload file is always generated no matter the value of these parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, agree that it can be removed here.
@nicolas-grekas Do you have an idea where is the best place to put a note about these flags should be false with preload enabled?

Copy link
Member

@nicolas-grekas nicolas-grekas Nov 30, 2020

Choose a reason for hiding this comment

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

container.dumper.inline_factories should be true with preloading if I understood correctly, and container.dumper.inline_class_loader should be false?

This could be added as a ..tip note maybe?

Copy link
Contributor Author

@ITernovtsii ITernovtsii Nov 30, 2020

Choose a reason for hiding this comment

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

container.dumper.inline_factories should be true with preloading if I understood correctly, and container.dumper.inline_class_loader should be false?

Correct

This could be added as a ..tip note maybe?

I think it's kind of a hard requirement to have inline_class_loader: false, to avoid unexpected errors.

What do you think about this wording?

The only requirement is that you need to set parameters
container.dumper.inline_factories: true and container.dumper.inline_class_loader: false,
to disable performance improvements designed for execution without preload.

Let me know if it should be .. tip:: or new wording is correct.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's kind of a hard requirement to have inline_class_loader: false, to avoid unexpected errors.

That's not a requirement, it works without this setting. If not, that should be reported and fixed.

I'm not sure anymore that we should add anything here, this is really a minor difference.
Let's just remove that sentence.

Copy link
Contributor Author

@ITernovtsii ITernovtsii Dec 1, 2020

Choose a reason for hiding this comment

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

Let's just remove that sentence.

Ok, removed

That's not a requirement, it works without this setting. If not, that should be reported and fixed.

Ok, I'll report it as a bug separately, as it doesn't work well with preload enabled.

@OskarStark OskarStark added this to the 4.4 milestone Dec 2, 2020
@OskarStark
Copy link
Contributor

Thank you Ivan.

@OskarStark OskarStark merged commit cfa1442 into symfony:4.4 Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants