-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
perf: 优化hyperf启动耗时, 元数据分类缓存, 有效缩短扫描时间 #644
Conversation
现在增加了缓存机制,理论上扫描时,如果不清除缓存是不会扫描的。。 |
unset($exploded[count($exploded) - 1]); | ||
$dirPath = implode('/', $exploded); | ||
if (! is_dir($dirPath)) { | ||
mkdir($dirPath, 0755, true); | ||
} | ||
} | ||
|
||
$data = implode(PHP_EOL, [$pathsHash, $cacher->serialize()]); | ||
file_put_contents($this->cachePath, $data); | ||
$data = implode(PHP_EOL, [$pathsHash, base64_encode(serialize($meta))]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里缓存太大了。。整个 ast注解树都进来了,我下午改一下。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
典型的使用场景: 修改代码->停止服务->重启服务,
而此时就算开启缓存, 由于文件最后修改时间变更, 同样会触发全盘的缓存更新, 所以对于这种典型场景, 缓存就失去了意义
此时 app 和 vendor 分别缓存的优势就体现出来了, 因为对于 hyperf 的使用者来说, 仅会修改 app 下的代码 @limingxinleo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @daodao97 !!!
由于常规开发中 vendor 下的代码一般不会被修改, 所以 vendor 下元数据缓存的利用率就会很高, 此处改动能有效降低
php bin/hyperf.php start
启动耗时本机硬件配置:
原本扫描时间: app 大概在 1s 左右, vendor 大概在 5s 左右
优化后缩短在1s左右