Skip to content
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

[6.x] Remove wasted file read when loading package manifest #32646

Merged
merged 1 commit into from
May 2, 2020

Conversation

TheNodi
Copy link
Contributor

@TheNodi TheNodi commented May 2, 2020

See #32645

This PR removes an unused file_get_contents of the packages manifest file.

How / Why
I was optimizing an application to have zero disk accesses, but I noticed the package manifest was read on every request, even though it is a PHP file and it should be cached by opcache.

I dug into the code and I find out there's a get of the manifest file before requiring it:

$this->files->get($this->manifestPath);

This translates to always reading the file into memory, and then throwing away the result.

$this->files->get was introduced in commit 683637a as a locking mechanism to prevent partial reads of the manifest file.
In commit 633a907 the locking was substituted by an atomic rename-based file write. The get called survived the refactor, resulting a no-op file_get_contents that just trashes the output.

Behavior Differences
When the build function is not capable of creating the file, the filesystem get would have thrown a FileNotFoundException. After this changes, an empty manifest is returned instead.
I don't think there is a way for build to silently fail a write, and the following line is explicitly checking the existence of the file. Hence I believe this is the intended behavior.

Filesystem get was introduced in laravel#25012 as a locking mechanism to prevent partial reads of the manifest file.
In laravel#26010 the locking was substituted by an atomic rename-based file write. The get called survived the refactor, resulting a noop file_get_contents that just trashes the output.

This commit removes the read entirely.
@TheNodi TheNodi force-pushed the manifest-remove-file-read-2 branch from 406b2d5 to 736ab17 Compare May 2, 2020 14:30
@taylorotwell taylorotwell merged commit eb8ba57 into laravel:6.x May 2, 2020
@TheNodi TheNodi deleted the manifest-remove-file-read-2 branch May 5, 2020 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants