Closed yoshinorin closed 7 months ago
Changes Missing Coverage | Covered Lines | Changed/Added Lines | % | ||
---|---|---|---|---|---|
lib/plugins/processor/post.ts | 21 | 24 | 87.5% | ||
<!-- | Total: | 21 | 24 | 87.5% | --> |
Files with Coverage Reduction | New Missed Lines | % | ||
---|---|---|---|---|
lib/plugins/processor/post.ts | 2 | 97.73% | ||
<!-- | Total: | 2 | --> |
Totals | |
---|---|
Change from base Build 8720332933: | -0.05% |
Covered Lines: | 9293 |
Relevant Lines: | 9389 |
@hexojs/core Dear team. This PR is ready for review. Thanks :)
I think other issues also related this PR
When slow?
config.post_asset_folder
is enabled.Why?
When
config.post_asset_folder
is enabled, Hexo calls thePost.toArray()
function for each file. The time complexity ofPost.toArray()
isO(n)
. Additionally, Hexo uses thePost.find
method to search for the post, and the average time complexity offind
is 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.findById
isO(1)
.Benchmark Environment
Below is bench env.
Benchmark Time (Before, After)
Processed data
Time
Command & Details
Gramegraph (Hot Processing only)
Before (Hot Processing)
After (Hot Processing)