Repository navigation
Description
Description
We need to read git log entries for:
- Content plugins
loadContent()lifecycle, to compute docs/blog/pages last update metadata whenshowLastUpdateTimeorshowLastUpdateAuthoris enabled - Sitemap
postBuild()lifecycle to compute the value of a<lastmod>tag from theroute?.metadata?.sourceFilePath(if provided by plugins, which may not be the case for third-party plugins)
As of Docusaurus 3.8, we queue commands like this one for each relevant file
git -c log.showSignature=false log --format=RESULT:%ct,%an --max-count=1 -- "i18n/fr/docusaurus-plugin-content-blog/releases/2.3/index.mdx"
Not exactly, here's a more accurate command:
In practice, we run this:
cd i18n/fr/docusaurus-plugin-content-blog/releases/2.3/
git -c log.showSignature=false log --format=RESULT:%ct,%an --max-count=1 -- "index.mdx"We do this because it's possible that users have git submodules, and the Git repo at the root may not contain the history of that specific file.
Performance problems
There are various performance bottlenecks in our implementation.
Main case
The git log command queueing works, but it remains a bottleneck, and there's probably room to improve things.
On a large 11k docs site, I noticed that loadContent() takes 24s when docs lastUpdate options are enabled, but only 4s when they are disabled, and these options are the main bottleneck of the loadContent() lifecycle for large sites.
I'm not sure how to improve the performance of this, but we likely have a few options to explore.
Useful resources:
- https://github.com/Brooooooklyn/simple-git
- https://www.nodegit.org/
- https://github.com/isomorphic-git/isomorphic-git
Suggested in:
- https://x.com/sebastienlorber/status/1927310075284111744
- https://bsky.app/profile/sebastienlorber.com/post/3lq5hx3kuec2d
Suggested again in:
- https://x.com/sebastienlorber/status/1965070340213834196
- https://bsky.app/profile/sebastienlorber.com/post/3lydik4nj4s27
We could also try to optimize the git commands. I think rev-parse and batching history read commands might work but we need to study that.
We could also try to create an incremental "last update" cache, reading the full history first, and then only reading from the newly added commits on rebuilds. This could also help to display the real last update data in dev. But maybe it would be slow to initialize for very large Git repos 🤷♂
i18n / codegen / untracked case
I've also noticed that the commands we issue are significantly slower for untracked Git files. This is usually the case:
- when downloading i18n mdx files from Crowdin
- when using codegen plugins creating untracked MDX files before running
docusaurus build
This can be seen locally on our own website on a localized build after downloading French translation files:
[PERF] Build > en > Load site - 4.53 seconds!
[PERF] Build > en > postBuild() - 3.34 seconds!
[PERF] Build > fr > Load site - 6.15 seconds!
[PERF] Build > fr > postBuild() - 11.53 seconds!It is unexpected that a French site build has a slower loadContent() and postBuild() compared to the English site.
The impact is even more significant on our Netlify CI, not as powerful as my mac M3 Pro
[PERF] Build > en > Load site - 5.71 seconds!
[PERF] Build > en > postBuild() - 12.78 seconds!
[PERF] Build > fr > Load site - 104.85 seconds!
[PERF] Build > fr > postBuild() - 203.77 seconds!
[PERF] Build > pt-BR > Load site - 191.19 seconds!
[PERF] Build > pt-BR > postBuild() - 298.34 seconds!
[PERF] Build > ko > Load site - 265.14 seconds!
[PERF] Build > ko > postBuild() - 372.63 seconds!
[PERF] Build > zh-CN > Load site - 352.54 seconds!
[PERF] Build > zh-CN > postBuild() - 449.76 seconds!Note: there's likely a logging issue (or something worse 🤔), numbers look like they accumulate and are not expected to grow like that, but we can already see that loadSite() and postBuild are much slower on localized sites.
It seems that the postBuild() hook takes more time for subsequent locales in practices so I suspect something really weird is happening here, but I can't reproduce it locally yet.
Duplicated work
If a file is not tracked by Git and the history couldn't be read in loadContent(), then we try to read it again in postBuild(), which, as described above, is quite slow.
This should be easy to fix so I'll handle this right now in #11211
Design issue
There are cases where we know for sure there's no last update metadata available. It should be possible to configure the site or plugins to avoid reading the Git history entirely. It's probably possible today through parseFrontMatter and process.env.DOCUSAURUS_CURRENT_LOCALE, but it is clearly not intuitive and we should provide better APIs.
Examples include:
- i18n sites: if translations are all downloaded from Crowdin, we likely don't want to read the last update metadata from Git for any file in the untracked
i18nfolder. - plugins using code-generation: we have various third-party plugins that generate MDX files that our content plugins will then read. An example is our own Changelog plugin. It should be possible to configure our content plugins so that they directly emit
nullvalues instead of running uselessgit logcommands.
In general, we probably want to introduce a global siteConfig.readLastUpdateData callback hook so that it's possible to implement other strategies that are not related to Git.
Here's an example usage based on a pseudo-implementation:
const siteConfig = {
readLastUpdateData: async (filePath, utils) => {
if (filePath.startsWith("i18n")) {
return null;
}
if (filePath.startsWith("changelog")) {
return utils.readFromFS(filePath);
}
return utils.readFromGit(filePath);
}
}
Activity
[-]Performance issues related to `git log` commands to read last update metadata[/-][+]Performance issue in `git log` commands to read last update metadata[/+]slorber commentedon May 28, 2025
The
git logissue seriously affects our CI build times.Those are times measured on Netlify on cold builds (no Rspack persistent cache)
Before any optimization:
After the duplicate call optimization:
After the local i18n opt-out optimization:
Our CI spends approximately 10min to setup things (initialization, building the monorepo, building and downloading Crowdin site translations...)
So, optimizing these
git logcalls and removing useless ones can have a very impactful result on Docusaurus build times, depending on the site.In our case,
docusaurus buildwent from 34min to 6min 🔥. We now need to figure out how to ship these improvements to the community, in a way that preferably doesn't require complex configuration optimizations.slorber commentedon May 30, 2025
I spent way too much time trying to figure out why
git logcalls are slow in our Netlify CI, and keep increasing as we build more locales. I'm not even sure this affects anyone apart us right now so I'm going to stop and move on for now, but please let me know if you are affected as well.Here's some notes from various experiments run from this PR: #11218
To make feedback quicker, I versioned the i18n translations from Crowdin to avoid downloading them (slow).
Git log benchmarks
Here's a local git log command benchmark. Options we use are not super relevant, but we can clearly see that it's slower for an untracked file
ignored/architecture.mdx.Note: I didn't run these commands on Netlify, that could be worth giving it a try if possible.
The problem doesn't seem related to the extra args we use.
Tracked vs non-tracked
Although
git logcommands are slower for untracked files, the difference should be in the order of less than 100ms, and doesn't explain why our CI would take up to 20 seconds to run a single command.Adding
i18nto Git didn't change that, so the problem doesn't seem related to tracked vs non-tracked.Execa vs child_process, shell vs non-shell
I tried removing Execa in favor of a simpler child_process integration:
This didn't lead to any significant improvement.
Note: we use execa with
shell: true. It's possible (and even recommended by Execa) to not use a shell (because apparently it's slower and less secure), but from my tests I can clearly see it's faster locally to use the shell option (with both execa/child_process).Using
git ls-filesI tried running a git command upfront to check if the file is tracked, but it didn't improve anything
slorber commentedon May 30, 2025
😢 this also affect GitHub Actions:
https://github.com/facebook/docusaurus/actions/runs/15351301297/job/43199950972?pr=11218
I tried running the exact same CI commands locally and didn't encounter this problem.
slorber commentedon Sep 8, 2025
Apparently someone else encountered that problem: #11398
markerikson commentedon Sep 10, 2025
Have you looked into using a Git library like https://github.com/nodegit/nodegit or https://github.com/isomorphic-git/isomorphic-git ? Might conceivably be faster than spawning a bunch of processes.
Josh-Cena commentedon Sep 10, 2025
I agree, no need to spawn processes here.
slorber commentedon Sep 10, 2025
Yes, those libraries are listed in the issue description already as solutions to consider.
From what I remember:
Definitively agree that we shouldn't spawn one process per file. Retrieving the full Git history with timestamps/authors is relatively fast even for a repo like ours that has 10000+ commits.
But we also need to take into account:
getLastUpdate()function in various plugins and plugin steps (we can't read everything upfront globally)fuma-nama commentedon Sep 14, 2025
@slorber not sure if you've found other solutions, I found this is much faster on my machine:
you may batch reads to optimize the performance
slorber commentedon Oct 24, 2025
FYI, here's a follow-up issue where we'll see if the e18e community could be interested in helping us solve this perf bottleneck efficnetly once for all: e18e/ecosystem-issues#216
Dharya-dev commentedon May 25, 2026
Been digging into this while working on the VCS code recently — thought I'd share some observations and concrete ideas.
Where the bottleneck actually lives
The eager strategy (
getGitRepositoryFilesInfo) already does the right thing architecturally — onegit log --name-statuscall vs N individual process spawns. But there are still a few places where perf leaks through:1. The stdout buffer problem
Right now the full
git logoutput gets buffered into a single string (maxBuffer: 20 * 1024 * 1024). For repos with 10k+ commits and lots of files per commit, that string can get massive. Parsing it withsplit('\n')then allocates another copy of the entire thing as an array. On CI runners with limited memory, this also risks GC pressure spikes.A streaming approach using
execa's stdout stream + readline would let you process line-by-line without buffering the full output:This alone should cut peak memory usage roughly in half for large repos.
2. The untracked file slowdown on CI
@slorber already noted this —
git logfor untracked files (i18n downloads, codegen output) is disproportionately slow because Git has to scan the entire history to confirm the file was never committed. On CI environments with shallow clones or limited I/O, this compounds badly.The eager strategy sidesteps this by design (untracked files just won't appear in the map), but the ad-hoc fallback still hits it. One low-hanging fix: before calling
git logfor a file, check if it's tracked withgit ls-files --error-unmatch <file>. That's essentially instantaneous and avoids the expensive full-history scan entirely. I knowFileNotTrackedErrorexists but it fires after the slowgit logcompletes.3.
git last-modified(Git 2.52+)This is worth watching closely. The command is designed exactly for this use case — it reads the commit-graph directly instead of walking the full log, which makes it orders of magnitude faster for "what's the latest commit touching this file?" queries. Two caveats though:
commit-graphto be built (usually automatic in modern Git, but not guaranteed on all CI)Could be a good candidate for a future
VcsGitLastModifiedstrategy — basically a drop-in for the ad-hoc approach but without the per-file process overhead, sincegit last-modifiedaccepts multiple paths.4. In-process Git (isomorphic-git)
Spawning processes is inherently expensive — each one costs a fork + exec + shell init.
isomorphic-gitreads the.gitdirectory directly in JS, eliminating that overhead completely. The tradeoff is it's pure JS so raw git operations are slower than native git, but for the specific "walk commits and map files to timestamps" workload, the savings from not spawning 11k processes would almost certainly dominate.Quick sketch of what this could look like:
The catch:
isomorphic-gitdoesn't have a direct--name-statusequivalent, so you'd need to diff trees between commits. That's more code, but it's a one-time implementation cost.What I'd actually recommend doing (in order of effort/impact)
git ls-filesbefore falling back togit login the ad-hoc strategygit last-modifiedonce it stabilizes — could replace the ad-hoc strategy entirely without needing the full log parseThe streaming fix (#1) is probably a ~20 line change and would help everyone. Happy to put up a PR for that if there's interest.
slorber commentedon Jul 10, 2026
Note: simple-git recently added the APIs we'd need to implement a new ad-hoc strategy on top of it: https://x.com/Brooooook_lyn/status/2074827514275574153