vuepress / core

Vue-Powered Static Site Generator
https://vuepress.vuejs.org
MIT License
2.17k stars 922 forks source link

perf: implement custom routes #1447

Closed Mister-Hope closed 5 months ago

Mister-Hope commented 7 months ago

Description

This pr reduces output size and improves performance at the same time.

Including:

merging page data and component into 1 chunk

Usually page data chunk is small (<1kb), and with shouldPreload shouldPrefetch and HTTP1.1, it will affect network. Merging them to 1 chunk almost reduce half of the chunk amount. And do not have negetive influencea as they are always fetch together.

avoid heavy operation with router.resolve

Removing duplicated route records with redirects and maps holding data, components

Now a single map holds all pages info and pageKey and a redirection map are used at client:

Breaking changes

New Recommendations

Other notes

To support clean url (e.g.: navigating to /a/b and resolve /a/b.html to /a/b), we improved generation of htmlRelativePath and htmlPath on Page object

Benchmark

Ci result while finishing official docs page-render stage:

Before(main) After
2.5-3.9s 1.4-2.8s

Local test result with a 1 million words project https://innenu.com/:

Before(main) After
186.22s 108.11s

RFC

BTW, if we drop markdown link support, we can have higher performance.

I would upvote to drop support for markdown links, since we already convert every markdown link in markdown files to <VPLink> with .html suffix.

What do you think if we add a router field in config files with options like:

router: {
  cleanUrl: true,
  resolveMarkdownLink: true,
  // ...
}
coveralls commented 5 months ago

Pull Request Test Coverage Report for Build 7766614992


Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/bundler-vite/src/build/resolvePageChunkFiles.ts 0 1 0.0%
packages/cli/src/commands/dev/handlePageUnlink.ts 0 1 0.0%
packages/client/src/composables/siteData.ts 0 1 0.0%
packages/client/src/setupGlobalComponents.ts 0 1 0.0%
packages/cli/src/commands/dev/handlePageAdd.ts 0 2 0.0%
packages/cli/src/commands/dev/handlePageChange.ts 0 2 0.0%
packages/client/src/composables/routes.ts 0 2 0.0%
packages/core/src/app/appPrepare.ts 0 2 0.0%
packages/core/src/app/prepare/preparePageChunk.ts 1 3 33.33%
packages/client/src/router/resolveRoute.ts 0 4 0.0%
<!-- Total: 21 101 20.79% -->
Totals Coverage Status
Change from base Build 7670827817: -0.4%
Covered Lines: 675
Relevant Lines: 1716

💛 - Coveralls
meteorlxy commented 5 months ago

perf: implement custom routes

BREAKING CHANGE: vue-router's route records have been replaced by custom route records to get better performance. It should not break common usage, but could be a potential breaking change for some themes. vue-router is suitable for SPAs, but not for static sites. It has a negative impact on the performance of vuepress sites, especially large-scale ones. In the long run we'll replace vue-router with a light-weighted custom router totally, but we'll try to keep the compatibility for sure.

Mister-Hope commented 5 months ago

LGTM

Mister-Hope commented 5 months ago

LGTM