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

vfsStreamDirectory::getChild() has absurd complexity #256

Open
mvorisek opened this issue May 28, 2021 · 2 comments
Open

vfsStreamDirectory::getChild() has absurd complexity #256

mvorisek opened this issue May 28, 2021 · 2 comments

Comments

@mvorisek
Copy link

mvorisek commented May 28, 2021

image

captured when the PrestaShop/Smarty caching is conigured to VFS like:

use org\bovigo\vfs\vfsStream;

$vfsSmartyRoot = vfsStream::setup('smarty', 0000);
$vfsSmartyCompile = vfsStream::newDirectory('compile')->at($vfsSmartyRoot);
$vfsSmartyCache = vfsStream::newDirectory('cache')->at($vfsSmartyRoot);

global $smarty;
$smarty = new SmartyCustom();
$smarty->setConfigDir([]);
$smarty->setCompileDir($vfsSmartyCompile->url());
$smarty->setCacheDir($vfsSmartyCache->url());

in https://github.com/PrestaShop/PrestaShop/blob/1.7.7.4/config/smarty.config.inc.php#L37

and basic page like /index.php is opened.

I belive there is some exponential complexity when traversing directories with depth like 10 as xdebug profiler shows for 2181 calls of getContent getChild is executed more than million times.

Callers:

image


image

@mvorisek mvorisek changed the title Somethings has absurd complexity vfsStreamDirectory::getChild() has absurd complexity May 28, 2021
@jaapio
Copy link
Contributor

jaapio commented May 29, 2021

Hi,

To get started, I think you didn't have a look at the code in this method. If you did, you would have noticed that this method has some recursion. Maybe there is some bug in there, but I cannot see in your reports what the actual calls are about. The method itself isn't that complex.

I would like to ask you to re-think your post, although it provides a lot of information about how you are using vfsStream, it doesn't really provide any information about what we as maintainers can do to fix this issue. If it was an issue in vfsStream. It would be useful if you could provide us some more information about what the arguments of these calls are.

Please keep in mind that some caching libraries have odd file structures which are optimized to do quick inode lookups which do work very well in regular filesystems. But will not perform as nice in vfsStream. Therefor vfsStream might not be the right choice for you to cache your smarty templates.

@mvorisek
Copy link
Author

I belive the deeply nested calls are invoked from here - https://github.com/bovigo/vfsStream/blob/v1.6.8/src/main/php/org/bovigo/vfs/vfsStreamDirectory.php#L183 - it iterates over all children and hasChild calls getChild again.

I belivery it can be easily replicated when you create vfs with depth like 3 and 3 files in each directory.

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

No branches or pull requests

2 participants