hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
39.57k stars 4.86k forks source link

WIP: perf(router): avoid calling `set` when the generated data unmodified #5482

Open yoshinorin opened 6 months ago

yoshinorin commented 6 months ago

What does it do?

When any file is modified, even unchanged routes are updated (the set method is called). Additionally, in the set method, EventEmitter's emit is called. So, events to be fired many times (number of assets) whenever a single file is updated.

Maybe, it should be fine to call the set method only for the modified files.

Screenshots

N/A

Pull request tasks

github-actions[bot] commented 6 months ago

How to test

git clone -b perf/router-refresh https://github.com/hexojs/hexo.git
cd hexo
npm install
npm test
github-actions[bot] commented 6 months ago

Flamegraph

https://c364a668e1e10e5ea65d2aa332677e6be4f3a292-14-hexo.surge.sh/flamegraph.html https://c364a668e1e10e5ea65d2aa332677e6be4f3a292-16-hexo.surge.sh/flamegraph.html https://c364a668e1e10e5ea65d2aa332677e6be4f3a292-18-hexo.surge.sh/flamegraph.html

yoshinorin commented 6 months ago

The test cases for the watcher are failing.

Now green. Use unique files for each test for watch. Because using the same files (test.txt) as other tests caused failures. Perhaps caused by caching or something similar, but I'm not sure.

coveralls commented 6 months ago

Pull Request Test Coverage Report for Build 8870147837

Details


Totals Coverage Status
Change from base Build 8800035659: 0.0%
Covered Lines: 9297
Relevant Lines: 9393

💛 - Coveralls
yoshinorin commented 6 months ago

I've noticed that when db.json exists before hexo s execution, CSS files and others aren't registered to the route in this PR. This is likely related to the tests failing when the file test.txt is used. I'll investigate.

yoshinorin commented 6 months ago

I've noticed that when db.json exists before hexo s execution, CSS files and others aren't registered to the route in this PR. This is likely related to the tests failing when the file test.txt is used. I'll investigate.

It seems that the _routerRefresh method is called not only for updating the router but also for initializing the router. Therefore, it seems necessary to make changes such as separating the method for initialization and updating.