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

refactor(list_archives): Reduce calls to date.format() #4011

Merged
merged 1 commit into from
Dec 27, 2019

Conversation

dailyrandomphoto
Copy link
Member

What does it do?

Continuation of #4007.

list_archives will call date.locale(lang), date.format(format) a lot of times, especial if set to relative_link: true. (fragment_cache was disabled)

This PR change makes list_archives call date.locale(lang), date.format(format) once per group.

How to test

git clone -b improve-list_archives https://github.com/dailyrandomphoto/hexo.git
cd hexo
npm install
npm test

Pull request tasks

  • Add test cases for the changes.
  • Passed the CI test.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.002%) to 97.087% when pulling cdea2aa on dailyrandomphoto:improve-list_archives into 8fae1a6 on hexojs:master.

@dailyrandomphoto
Copy link
Member Author

A benchmark using a hexo dummy website (with 900 posts):

Measure 5 times and calculate the average for each benchmark.

Benchmark conditions:

Node.js 8

Total time (Cold) Save DB (Cold) Memory (Cold) Total time (Hot) Save DB (Hot) Memory (Hot)
master-1 148.839s 2.38s 1102.397MB 125.162s 2.111s 1181.39MB
master-2 81.695s 2.219s 1112.943MB 63.956s 1.973s 1172.119MB
this PR 77.795s 2.152s 1109.003MB 59.523s 1.956s 1174.696MB

Node.js 10

Total time (Cold) Save DB (Cold) Memory (Cold) Total time (Hot) Save DB (Hot) Memory (Hot)
master-1 121.885s 2.045s 1203.274MB 106.81s 1.859s 1242.954MB
master-2 68.21s 2.045s 1167.641MB 53.912s 1.888s 1206.12MB
this PR 67.258s 2.039s 1189.209MB 53.68s 1.896s 1203.623MB

Node.js 12

Total time (Cold) Save DB (Cold) Memory (Cold) Total time (Hot) Save DB (Hot) Memory (Hot)
master-1 127.652s 2.065s 1128.723MB 114.08s 1.953s 1210.77MB
master-2 69.073s 2.112s 1141.249MB 54.851s 1.945s 1183.367MB
this PR 66.376s 2.084s 1146.682MB 51.547s 1.994s 1169.289MB

Node.js 13

Total time (Cold) Save DB (Cold) Memory (Cold) Total time (Hot) Save DB (Hot) Memory (Hot)
master-1 125.619s 2s 1129.541MB 114.066s 1.898s 1181.748MB
master-2 69.611s 2.1s 1125.007MB 54.739s 1.915s 1158.469MB
this PR 68.913s 2.034s 1116.61MB 53.455s 1.913s 1168.279MB

@@ -93,6 +93,19 @@ describe('list_archives', () => {
].join(''));
});

it('show_count + style: false', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for improve test coverage (#3984)

@@ -123,6 +136,21 @@ describe('list_archives', () => {
].join(''));
});

it('transform + style: false', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for improve test coverage (#3984)

Copy link
Member

@SukkaW SukkaW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

I have already noticed some performance bottleneck at moment.js during the study of the flamegraph. I am glad to see you start to do some optimizations on it.

@SukkaW SukkaW merged commit 4687816 into hexojs:master Dec 27, 2019
thom4parisot pushed a commit to thom4parisot/hexo that referenced this pull request Jan 17, 2020
@SukkaW SukkaW mentioned this pull request Jul 25, 2020
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants