-
-
Notifications
You must be signed in to change notification settings - Fork 5k
perf(processor/post): improve processing speed when config.post_asset_folder is enabled
#5473
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
Conversation
Pull Request Test Coverage Report for Build 8753005942Details
💛 - Coveralls |
config.post_asset_folder is enabledconfig.post_asset_folder is enabled
…t_folder` is enabled
131d295 to
9385c81
Compare
2790445 to
44a14de
Compare
| const Post = ctx.model('Post'); | ||
| const id = file.source.substring(ctx.base_dir.length); | ||
| const doc = PostAsset.findById(id); | ||
| const postAsset = PostAsset.findById(id); |
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 renamed unclear naming.
|
|
||
| if (doc) { | ||
| return doc.remove(); | ||
| // NOTE: Probably, unreachable. |
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.
Probably, will not be reached here unless the user intentionally changes the values in db.json. But, I'm not sure about this, so I haven't removed it.
config.post_asset_folder is enabledconfig.post_asset_folder is enabled
|
@hexojs/core |
…t_folder` is enabled (hexojs#5473)
…t_folder` is enabled (hexojs#5473)
|
The Windows sep is a backslash. Assuming the ID is |
Thank you. I'll check it if I can find time this weekend or next weekend. |
Will be fixed in #5704 |
I think other issues also related this PR
When slow?
config.post_asset_folderis enabled.Why?
When
config.post_asset_folderis enabled, Hexo calls thePost.toArray()function for each file. The time complexity ofPost.toArray()isO(n). Additionally, Hexo uses thePost.findmethod to search for the post, and the average time complexity offindis alsoO(n).So, if there are 100 articles and 100 files, the time complexity would be
O(100 * 100 * 100) = O(n^3).How to solve?
Avoid calling
Post.toArray(). Instead, we will search based on whether the directory where the files are stored (assetDir) matches. Also, if the file found withPostAsset, usePost.findById. The time complexity ofPost.findByIdisO(1).Benchmark Environment
Below is bench env.
Machine
Hexo and Node.js
package.json_config.ymlTheme
I'm using a theme that I've delete many features from https://github.com/LouisBarranqueiro/hexo-theme-tranquilpeak.
Benchmark Time (Before, After)
Processed data
Time
Command & Details
Cold Processing (run hexo clean before generate)
Hot Processing (run hexo clean before generate)
After
Cold Processing (run hexo clean before generate)
Hot Processing (run hexo clean before generate)
Gramegraph (Hot Processing only)
Before (Hot Processing)
After (Hot Processing)