-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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(cache): Improve cache, Reduce Memory Usages #3756
Conversation
…n enable cache on watch mode.
…les. Added at (hexojs@e8e45ed#diff-b9bb6fa7bb069bab9948daba90c6c3b2). Should enable save cache for rendered contents when run server mode.
LGTM. I will run a benchmark on this. |
With fragment cache enabled:
With fragment cache disabled:
I can see this PR has its generation speed more or less as same as the current master branch. I am wonder why @tommy351 implement |
Fragment cache reminds me of this issue #2503, specifically this comment (I highlighted the last line):
By enabling Fragment Cache for every mode, I believe this PR is also an improvement to the |
lib/plugins/helper/fragment_cache.js
Outdated
const cache = {}; | ||
let cache = {}; | ||
|
||
ctx.on('generateBefore', function() { |
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.
I think can use arrow function?
For At the beginning, Cache Of Rendered HTML was enabled for Lines 362 to 367 in e8e45ed
But from this commit it was disabled by Lines 362 to 368 in c313b5f
I think @tommy351 wants to disable it for If this feature useful for |
Fragment Cache(introduced in #637) can improve performance a lot.
However, some partial which output is different between pages should turn it off.
Like these partial(widget) can turn it on:
|
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.
LGTM!
* test(cache): verify whether the cache works properly * fix(fragment_cache): reset the cache on generateBefore event so we can enable cache on watch mode. * fix(cache): disable save cache for rendered contents when generate files. Added at (hexojs@e8e45ed#diff-b9bb6fa7bb069bab9948daba90c6c3b2). Should enable save cache for rendered contents when run server mode.
What does it do?
Hexo uses a lot of memory to make a huge site.
This PR will reduce memory usages by modifying the usage of the unnecessary cache.
It can help with the "out of memory" related issues. (e.g., #3350 #3311 #1769 #1763 #1735 #1529)
There are two kinds of caches that hexo using
I've found something that can be improved a little bit to reduce memory usages.
Before
In
generate
mode, Use Cache Of Rendered HTML should befalse
, since each route just be called once. The unnecessary cache uses a lot of memory.On the other hand, in
server
mode, Use Cache Of Rendered HTML should betrue
, since each route will be called several times. After enabling the cache, the route will respond more quickly from second requests.In
generate + watch
mode, generating a huge site will be slower thangenerate
mode since Use Fragment Cache is disabled. Use Fragment Cache should always be enabled to speed up generating.After
This PR will change the usages of caches to
How to test
Compare: Before vs. After
Before
git clone https://github.com/dailyrandomphoto/hexo-huge-site-test.git cd hexo-huge-site-test npm install npm run g
Environment & Result
After
change the hexo dependency to dailyrandomphoto/hexo#improve-cache in package.json
Environment & Result
Screenshots
Before
After
Pull request tasks