Movatterモバイル変換


[0]ホーム

URL:


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

Remove non-autoloadable classes from preload#44380

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
jderusse wants to merge1 commit intosymfony:6.1fromjderusse:preload

Conversation

@jderusse
Copy link
Member

QA
Branch?5.3
Bug fix?yes
New feature?no
Deprecations?mp
TicketsFix#44364
LicenseMIT
Doc PR

When a class is required in a preloaded file, all the type hinted properties have to be auto-loadable. (sees discussion in linked issue)

This could be an issue for classes likeBodyRenderer that have a property typehinted with an optional dependency.

privateHtmlConverter$converter;
publicfunction__construct(Environment$twig,array$context = [])
{
$this->twig =$twig;
$this->context =$context;
if (class_exists(HtmlConverter::class)) {
$this->converter =newHtmlConverter([
'hard_break' =>true,
'strip_tags' =>true,
'remove_nodes' =>'head style',
]);
}

Sometime, the relation is tricky. For instanceRedisAdapter usesRedisTrait that have a property$redis typehintedRedisClusterProxy that have a property typehintedPredis\ClientInterface => butPredis is an optional dependency

When dumping the Preload classMap, this PR now check if all the properties are auto-loadable.

@carsonbotcarsonbot added this to the5.3 milestoneDec 1, 2021
@jderussejderusseforce-pushed thepreload branch 3 times, most recently fromea33197 to83dbe08CompareDecember 1, 2021 07:42
Copy link
Member

@nicolas-grekasnicolas-grekas 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.

I really like the idea!

I think the current state of the implementation won't work: shouldn't a class that depends on a non-preloadable class also be flagged as non-preloadable?

I also have one fear: in practice, how many classes will this exclude from preloading (especially considering the previous point?) The more typed properties we use, the less classes will be preloaded.

Or maybe we shouldn't be concerned because PHP 8.1 doesn't have the issue, and preloading is also mostly dead since 8.1. We could even consider deprecating our dedicated logic for it.

}
$this->preloadableCache[$class] =true;// prevent recursion

if (!class_exists($class) && !interface_exists($class,false) && !trait_exists($class,false)) {
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

beware, switched fromclass_exists($class, false) toclass_exists($class)

@jderussejderusseforce-pushed thepreload branch 3 times, most recently from8c47b47 toca03364CompareDecember 1, 2021 09:35
@stof
Copy link
Member

stof commentedDec 1, 2021

preloading is also mostly dead since 8.1

@nicolas-grekas what do you mean with this sentence ?

@nicolas-grekas
Copy link
Member

I mean that preloading might not be worth the trouble it is to maintain and setup anymore...

@jderusse
Copy link
MemberAuthor

I think the current state of the implementation won't work: shouldn't a class that depends on a non-preloadable class also be flagged as non-preloadable?

Indeed, I missed 3 points:

  1. The Preloader browse the classes, properties and methods parameters to discover more classes.

This is now fixed by doing the ~same thing in PHPDumper.

  1. The preloader usesget_declared_classes to browse more classes

This one is tricky because, in PhpDumper, I can't easily do the same for each discovered class. That would require a tokenizer, or callingget_declared_classes in an isolated process => big overhead.

I fixed it by pre-filling the$preloaded parameter of the Preloader to prevent it to browse the classes I known to be not pre-loadable.

  1. The generated.preload file is full ofrequire_once included in the Dumped Container

I have no choice but removing the container from the.preload.php file. (in my case, the code preloaded 2300 files before, and 1900 after that change)

@fabpot
Copy link
Member

This one is quite important as currently, Symfony 6.0 is broken when using pre-loading.

@fabpot
Copy link
Member

See#44494 for an alternative

@fabpot
Copy link
Member

Closing in favor of#44494

@fabpotfabpot closed thisDec 8, 2021
@jderusse
Copy link
MemberAuthor

reopening: Removing typehinted property insymfony/symfony: 6.0 is a workaround for our internal classes, but the bug still exists for other dependencies.

The current implementation of the preloads script discovers all classes used by the end-user. Every third-party package/bundle with type hinted property will hit the same bug.

Worst case, this PR should be merged in 6.1 and type-hint re-added.

@jderussejderusse reopened thisDec 8, 2021
fabpot added a commit that referenced this pull requestDec 9, 2021
This PR was merged into the 6.0 branch.Discussion----------Remove FQCN type hints on properties| Q             | A| ------------- | ---| Branch?       | 6.0| Bug fix?      | yes| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->| Tickets       |Closes#44364| License       | MIT| Doc PR        | n/aThis is an alternative for#44380.Basically, we are removing all property type hints on 6.0 and reverts that for 6.1.Commits-------52aaa56 Remove FQCN type hints on properties
@fabpot
Copy link
Member

This one should be rebased on 6.1 then.

@fabpotfabpot modified the milestones:5.3,6.1Dec 11, 2021
@jderussejderusse changed the base branch from5.3 to6.1December 11, 2021 18:35
@nicolas-grekas
Copy link
Member

The preloader uses get_declared_classes to browse more classes

This one is tricky because, in PhpDumper, I can't easily do the same for each discovered class. That would require a tokenizer, or calling get_declared_classes in an isolated process => big overhead.

Could we fix this by registering an autoloader that only collects autoloaded symbols before the real autoloader?

The generated .preload file is full of require_once included in the Dumped Container

I have no choice but removing the container from the .preload.php file. (in my case, the code preloaded 2300 files before, and 1900 after that change)

You mean in the initializer that is called on the first call toset() since#44010, right?
We might be able to fix this by not callingset() but listing the files/classes in the preload script instead, isn't it?

@nicolas-grekas
Copy link
Member

nicolas-grekas commentedDec 13, 2021
edited
Loading

What about another alternative: deprecate generating the preload script at all?

Since 8.1, preloadingprovides almost no benefits to me.

Preloading is (was?) also sensitive to "over-preloading" (aka preloading too many classes, making it under-perform due to hash table overhead), so that any benefits provided by preloading might easily be canceled by having it not properly configured. And since configuring it is quite difficult, the gain might not be reachable in practice.

Also, I guess 8.1 is able to cache the same class/symbol for different paths, while preloading cannot.

I'd be interested in knowing@nikic's thoughts on the topic!

Or we could make the preloading script extremely simpler, eg preloading only composer+some very basic stuffs.

@nicolas-grekas
Copy link
Member

BTW, would it possible to turn that fatal error into a warning on PHP 8.0, as a bugfix?

@nikic
Copy link
Contributor

BTW, would it possible to turn that fatal error into a warning on PHP 8.0, as a bugfix?

Nope, the fatal error is required for correctness in 8.0.

As to preloading in general, the usefulness is greatly diminished with 8.1, but I don't really have data on whether there are any cases where it still makes sense.

@wouterj
Copy link
Member

As we've added the type to properties again in the 6.1-dev branch, what is needed to finish this PR? Is there anything I (or the community) can do to help move this forward?

@nicolas-grekas
Copy link
Member

Replaced by#45377

Thank you very much for providing this patch@jderusse, it's been critical to make an informed decision on the topic! 🙏

fabpot added a commit that referenced this pull requestFeb 25, 2022
This PR was squashed before being merged into the 6.1 branch.Discussion----------Bump minimum version of PHP to 8.1| Q             | A| ------------- | ---| Branch?       | 6.1| Bug fix?      | no| New feature?  | no| Deprecations? | no| Tickets       |Fix#44364| License       | MIT| Doc PR        | -While reviewing#44380, I wondered: why should we maintain such a complex piece of logic while only PHP 8.0 is affected?So here we are: what about bumping Symfony 6.1 to PHP 8.1 minimum?That would free ourselves from maintaining this workaround.The good news is that Ubuntu 22.04LTS will ship PHP 8.1, so that it's going to be easy to have it widely installed.Also, looking athttps://packagist.org/packages/symfony/framework-bundle/php-stats#6.0, early adopters of Symfony 6 are already using PHP 8.1 en masse, and it's growing fast.Let's do it?Commits-------b0217c6 Bump minimum version of PHP to 8.1
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@stofstofstof left review comments

@derrabusderrabusderrabus left review comments

Assignees

No one assigned

Projects

None yet

Milestone

6.1

Development

Successfully merging this pull request may close these issues.

Typehinted properties on missing class with preloading

8 participants

@jderusse@stof@nicolas-grekas@fabpot@nikic@wouterj@derrabus@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp