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

Appearance settings

Postpone native guessers instantiation in MimeTypeGuesser. #27323

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
wants to merge 1 commit into from

Conversation

vudaltsov
Copy link
Contributor

Q A
Branch? 2.7
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #27307
License MIT
Doc PR

In this PR I made singleton MimeTypeGuesser lazy. Now it registers FileinfoMimeTypeGuesser and FileBinaryMimeTypeGuesser only when guess() is called. Should improve performance.

I don't think it's a feature - more a fix... Can this be merged into 2.7?

*/
private function getGuessers()
{
if (!$this->nativeGuessersLoaded) {
Copy link
Contributor

@stloyd stloyd May 21, 2018

Choose a reason for hiding this comment

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

No need for new variable, just use: if (!$this->guessers) {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not going to work in case someone registers new guessers later with register(). Then native guessers will never be appended and that might affect the guessing process since there will be no default guessers.

if (!$this->nativeGuessersLoaded) {
// register all natively provided mime type guessers.

if (FileinfoMimeTypeGuesser::isSupported()) {
Copy link
Member

Choose a reason for hiding this comment

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

Just asking: couldn't we detect if native guessers are available during the application compilation with a compiler pass?

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, I understand what you are proposing. Yes, this can be done once while compilation. But then it's better not to use a Singleton and have just a normal ChainGuesser, empty by default. The problem is that MimeTypeGuesser as a Singleton is already used everywhere, so it's easier to fix it this way.

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone May 21, 2018
@vudaltsov
Copy link
Contributor Author

Status: Needs Review

@fabpot
Copy link
Member

fabpot commented May 23, 2018

This is a new feature (or put another way, this is not a bug fix), so it must be on the master branch.

@vudaltsov
Copy link
Contributor Author

Agree. I will rebase it at the end of the week.

// register all natively provided mime type guessers.

if (FileinfoMimeTypeGuesser::isSupported()) {
$this->guessers[] = new FileinfoMimeTypeGuesser();
Copy link
Member

Choose a reason for hiding this comment

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

this changes the existing behavior, as they are now registered at the end while the existing logic registers them before custom ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In existing code native guessers are prepended to an empty array in a private constructor. By the time guess is called, native loaders are always at the end of the array.

In this PR they are added later. So to have the same behavior, I add them to the end of the array in a reversed order.

Copy link
Member

Choose a reason for hiding this comment

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

ah, I forgot the fact that register was prepending the guessers

@vudaltsov
Copy link
Contributor Author

Status: Needs Review

@nicolas-grekas
Copy link
Member

Oops I'm sorry I missed this PR and made #27359 instead.
Looking at the implementations, #27359 is simpler and is free from any potential BC break, whereas here the call to "register" is bypassed.
I'm therefore closing here in favor of #27359.

Thank you @vudaltsov for working on this anyway!

@vudaltsov vudaltsov deleted the lazy-mime-type-guesser branch May 25, 2018 00:35
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.