Skip to content

Autoloader is not deterministic and possibly performs too many file stats #9619

Closed
bantu opened this Issue Jul 14, 2014 · 3 comments

6 participants

@bantu
ownCloud member
bantu commented Jul 14, 2014

When the autoloader currently receives a class to be loaded, it generates an array of possible paths that class may be found in. Furthermore it uses stream_resolve_include_path() to resolve these paths. This leads to a lot of unncessary "does that file exist" checks and provokes issues like #9524.

To fix this problem, the autoloader should be made entirely deterministic. That means, given a class name, the autoloader should take that class name and transform it into a file path (deterministically, without looking at the filesystem). Only this single file should be tried to be loaded.
If the file does not exist, an error should be generated (either hard by just using require or soft by performing file_exists() on that single file).
Furthermore the ownCloud autoloader should not make use of stream_resolve_include_path(). This should only be necessary for legacy libraries. These can probably be loaded via the Composer autoloader which ensures only necessary paths are traversed.

Please note that deterministic does not mean that different prefixes can not be used. It will still allow mapping the OCP prefix to the lib/public folder and OC to the lib/private folder.

@bantu bantu added the Tech. Debt label Jul 14, 2014
@bantu bantu changed the title from Autoloader is not deterministic and possibly performs too many file stats() to Autoloader is not deterministic and possibly performs too many file stats Jul 14, 2014
@AdamWill

I filed #9643 to cover the bit about using Composer's autoloader (not OC's) to handle bundled libraries.

@bantu
ownCloud member
bantu commented Jul 16, 2014

The "searching in all possible paths" feature might be in use by core apps. See e.g. https://github.com/owncloud/core/blob/master/apps/files_external/lib/owncloud.php which defines a class OC\Files\Storage\OwnCloud. This breaks determinism.

@butonic butonic added technical debt and removed Tech. Debt labels Sep 10, 2014
@DeepDiver1975 DeepDiver1975 modified the milestone: backlog Mar 21, 2015
@MorrisJobke
ownCloud member

This is more or less a duplicate of #13241 -> closing.

@MorrisJobke MorrisJobke removed this from the backlog milestone Jan 19, 2016
@DeepDiver1975 DeepDiver1975 added this to the backlog milestone Jan 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.