Skip to content

Cache the Git remote URL to speed up rendering hyperlinks#1940

Merged
th1000s merged 2 commits into
dandavison:mainfrom
charlievieth:cev/hyperlink
Nov 14, 2025
Merged

Cache the Git remote URL to speed up rendering hyperlinks#1940
th1000s merged 2 commits into
dandavison:mainfrom
charlievieth:cev/hyperlink

Conversation

@charlievieth

@charlievieth charlievieth commented Jan 11, 2025

Copy link
Copy Markdown
Contributor

This commit speeds up the rendering of hyperlinks by ~47x by caching the Git repos remote URL instead of fetching it each time a hyperlink is rendered.

Fixes #1939

Note

I am very new to Rust so I am very open to feedback and completely understand if you want to rewrite or abandon this entire PR (especially if for some reason the remote URL should not be cached). Additionally, I think the GitConfig should be responsible for storing the cached remote, but struggled to make that work due to borrowing, lifetimes, mutability, etc.

Benchmarks

The below benchmarks were ran in the root of Linux v6.12. We use head -c $((128 * 1024 * 1024)) to limit the amount of Git log data since otherwise benchmarking delta before this change takes a very long time.

TLDR: This change makes processing 128Mib of Git log output take 3.7 seconds instead of 176.1 seconds.

Without git remote caching

$ DELTA_PAGER='bash -c "time head -c $((128 * 1024 * 1024)) | pv --stats --output=/dev/null"' \
    git -c 'pager.log=delta --hyperlinks' log
 128MiB 0:02:56 [ 744KiB/s]
rate min/avg/max/mdev = 654979.457/764202.554/1108112.678/35667.893 B/s

real	2m56.063s
user	0m0.736s
sys	0m5.530s

With git remote caching (this change)

$ PATH="{PATH_TO_NEW_DELTA}:${PATH}"
$ DELTA_PAGER='bash -c "time head -c $((128 * 1024 * 1024)) | pv --stats --output=/dev/null"' \
    git -c 'pager.log=delta --hyperlinks' log
 128MiB 0:00:03 [34.6MiB/s]
rate min/avg/max/mdev = 35979500.033/36287504.626/36646720.334/263641.477 B/s

real	0m3.700s
user	0m0.205s
sys	0m1.690s

@th1000s

th1000s commented Jan 12, 2025

Copy link
Copy Markdown
Collaborator

Thanks for reporting this!

Caching is fine, the slowdown is from libgit2 being overly correct and assuming that the remote url could change while the program is running.
The PR can indeed be made simpler by using a RefCell to add interior mutability to the GitConfig, i.e. cached_remote: RefCell<Option<Option<String>>> with an not-yet-cached option layer, and another for the result of .find_remote(..).ok() - or maybe a custum enum is clearer.

@charlievieth charlievieth force-pushed the cev/hyperlink branch 2 times, most recently from aeb4fca to c184e5f Compare August 14, 2025 01:53
@charlievieth

Copy link
Copy Markdown
Contributor Author

@th1000s Took a while until I had some spare cycles to look at this again, but following your guidance I was able to use a OnceCell to embed the GitRemoteRepo struct into the GitConfig struct. Thank you again for your suggestions and would love another review if you have the time.

@charlievieth

Copy link
Copy Markdown
Contributor Author

@dandavison 1) Thank you for delta - it's incredible 2) Any chance you could enable the tests?

@dandavison

Copy link
Copy Markdown
Owner

Hi @charlievieth -- tests are running! I'm sorry that I personally am finding so little time to work on delta at the moment, but thank you very much for your work here.

@charlievieth

charlievieth commented Sep 5, 2025

Copy link
Copy Markdown
Contributor Author

@dandavison Thank you and I completely understand (I've only recently had the cycles to address my own OSS commits and projects).

The clippy failure that I get on this branch/PR are identical to the one I get when running make lint (aka cargo clippy) against the main branch (d5e0565). I'm fairly new to Rust so happy to look into the failure myself and include it into this branch or create a preceding PR (to merge before this one) that addresses the issue.

For context my rust toolchain is:

  • rustc 1.89.0 (29483883e 2025-08-04) (Homebrew)
  • clippy 0.1.89

Script used to check the delta of cargo clippy

#!/usr/bin/env bash

set -euo pipefail

TMP=$(mktemp -d)
TMP_MAIN="${TMP}/clippy.main.txt"
TMP_HYPER="${TMP}/clippy.hyperlink.txt"

if ! git remote -v | grep -q '^charlievieth'; then
    git remote add charlievieth https://github.com/charlievieth/delta.git
fi
git fetch --all

git checkout main
cargo clippy  &> "${TMP_MAIN}" || true

git checkout cev/hyperlink
cargo clippy  &> "${TMP_HYPER}" || true

(
    cd "${TMP}"
    git diff --no-index "$(basename "${TMP_MAIN}")" "$(basename "${TMP_HYPER}")"
)

Output (nothing applicable AFAIK):

diff --git a/clippy.main.txt b/clippy.hyperlink.txt
index 65e5421..71ee65e 100644
--- a/clippy.main.txt
+++ b/clippy.hyperlink.txt
@@ -71,4 +71,4 @@ help: use `'_` for type paths
     |                                                                              ++++

 warning: `git-delta` (bin "delta") generated 5 warnings
-    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.68s
+    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.70s

@dandavison

Copy link
Copy Markdown
Owner

If you'd like to deal with the clippy complaints then that would be great! I think the best way would be to open a PR for the clippy-related fixes against main and then rebase this on that.

@charlievieth

Copy link
Copy Markdown
Contributor Author

If you'd like to deal with the clippy complaints then that would be great! I think the best way would be to open a PR for the clippy-related fixes against main and then rebase this on that.

Created #2038 to address the clippy complaints.

@charlievieth

Copy link
Copy Markdown
Contributor Author

If you'd like to deal with the clippy complaints then that would be great! I think the best way would be to open a PR for the clippy-related fixes against main and then rebase this on that.

Created #2038 to address the clippy complaints.

@dandavison now that #2038 is merged any chance you can take a look at this PR?

@charlievieth

Copy link
Copy Markdown
Contributor Author

The clippy error reported here also occurs on the main branch.

th1000s and others added 2 commits November 14, 2025 10:07
This commit changes the GitConfig struct to cache the GitRemoteRepo,
which speeds up the rendering of hyperlinks by ~55x.

Fixes dandavison#1939
@th1000s

th1000s commented Nov 14, 2025

Copy link
Copy Markdown
Collaborator

Thank you for this improvement, and apologies for the delays. I also fixed the new v1.91 (which was released in the meantime) clippy warning.

Comment thread src/git_config/mod.rs
config_from_env_var: HashMap<String, String>,
pub enabled: bool,
repo: Option<git2::Repository>,
remote_url: OnceCell<Option<GitRemoteRepo>>,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice, a OnceCell is much better than RefCell`.

@th1000s th1000s merged commit 991d560 into dandavison:main Nov 14, 2025
13 checks passed
@charlievieth

Copy link
Copy Markdown
Contributor Author

@th1000s thank you for the review and for merging this PR!

@charlievieth charlievieth deleted the cev/hyperlink branch November 18, 2025 19:29
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Mar 26, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [dandavison/delta](https://github.com/dandavison/delta) | minor | `0.18.2` → `0.19.1` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>dandavison/delta (dandavison/delta)</summary>

### [`v0.19.1`](https://github.com/dandavison/delta/releases/tag/0.19.1)

[Compare Source](dandavison/delta@0.19.0...0.19.1)

This patch release fixes a release automation [bug](dandavison/delta#2127): release [0.19.0](https://github.com/dandavison/delta/releases/tag/0.19.0) did not include all release binaries.

#### What's Changed

- Fix CD: replace defunct ubuntu-20.04 runners by [@&#8203;dandavison](https://github.com/dandavison) in [#&#8203;2129](dandavison/delta#2129)

**Full Changelog**: <dandavison/delta@0.19.0...0.19.1>

### [`v0.19.0`](https://github.com/dandavison/delta/releases/tag/0.19.0)

[Compare Source](dandavison/delta@0.18.2...0.19.0)

Tons of improvements; thanks very much to all delta contributors.

**This release is missing several binaries due to a [bug in the GitHub Actions release workflow](dandavison/delta#2127). Please use <https://github.com/dandavison/delta/releases/tag/0.19.1> instead.**

#### What's Changed

- Do not double panic in FakeParentArgs::drop by [@&#8203;dvermd](https://github.com/dvermd) in [#&#8203;1856](dandavison/delta#1856)
- Improve blame file type detection ([#&#8203;1803](dandavison/delta#1803)) by [@&#8203;dvermd](https://github.com/dvermd) in [#&#8203;1829](dandavison/delta#1829)
- Use same example config in manual as README by [@&#8203;dandavison](https://github.com/dandavison) in [#&#8203;1879](dandavison/delta#1879)
- Clarify grep highlighter-related code by [@&#8203;dandavison](https://github.com/dandavison) in [#&#8203;1877](dandavison/delta#1877)
- Don't set colorMoved in introductory instructions by [@&#8203;dandavison](https://github.com/dandavison) in [#&#8203;1884](dandavison/delta#1884)
- Recommend zdiff3 merge.conflictStyle by [@&#8203;adamchainz](https://github.com/adamchainz) in [#&#8203;1260](dandavison/delta#1260)
- Add themes `weeping-willow`, `mirthful-willow` by [@&#8203;lvdh](https://github.com/lvdh) in [#&#8203;1864](dandavison/delta#1864)
- CI: switch to macos-13, as 12 will be unsupported soon by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;1890](dandavison/delta#1890)
- Add optional capture-output writer to run\_app() by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;1889](dandavison/delta#1889)
- Center-align README content by [@&#8203;dandavison](https://github.com/dandavison) in [#&#8203;1893](dandavison/delta#1893)
- Redundant Option Checks, Unwrap Safety by [@&#8203;sharma-shray](https://github.com/sharma-shray) in [#&#8203;1892](dandavison/delta#1892)
- Add console commands for git configuration by [@&#8203;harmtemolder](https://github.com/harmtemolder) in [#&#8203;1896](dandavison/delta#1896)
- Honor pager path when checking less version by [@&#8203;dandavison](https://github.com/dandavison) in [#&#8203;1903](dandavison/delta#1903)
- Rename some variables by [@&#8203;dandavison](https://github.com/dandavison) in [#&#8203;1904](dandavison/delta#1904)
- Delete now-unused pricate homebrew formula step from Makefile (III) by [@&#8203;dvermd](https://github.com/dvermd) in [#&#8203;1830](dandavison/delta#1830)
- Support {host} in hyperlinks by [@&#8203;dandavison](https://github.com/dandavison) in [#&#8203;1901](dandavison/delta#1901)
- Allow multiple hyperlinks per line by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;1909](dandavison/delta#1909)
- Clippy 1.83 by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;1918](dandavison/delta#1918)
- Support external subcommands: rg, diff, git-show (etc.) by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;1769](dandavison/delta#1769)
- Don't keep subcommand stdout around by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;1920](dandavison/delta#1920)
- hyperlink commit hashes of length 7 as well by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;1924](dandavison/delta#1924)
- clippy 1.84 fix by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;1938](dandavison/delta#1938)
- chore(deps): update git2 to use libgit2 1.9 by [@&#8203;chenrui333](https://github.com/chenrui333) in [#&#8203;1930](dandavison/delta#1930)
- Suggest minimum bat version in manual by [@&#8203;ernstki](https://github.com/ernstki) in [#&#8203;1941](dandavison/delta#1941)
- Upgrade unicode-width to v0.1.14 (but still < 0.2.0) by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;1937](dandavison/delta#1937)
- Update terminal-colorsaurus version to 0.4.8 by [@&#8203;rashil2000](https://github.com/rashil2000) in [#&#8203;1936](dandavison/delta#1936)
- Fix index out of bounds crash for '@&#8203;@&#8203;  @&#8203;@&#8203;' hunk header by [@&#8203;adamchainz](https://github.com/adamchainz) in [#&#8203;1995](dandavison/delta#1995)
- Tune themes weeping-willow, mirthful-willow by [@&#8203;lvdh](https://github.com/lvdh) in [#&#8203;2011](dandavison/delta#2011)
- clippy 1.88 fixes by [@&#8203;injust](https://github.com/injust) in [#&#8203;2016](dandavison/delta#2016)
- Fix diff output when a diff ends with a mode change by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;2023](dandavison/delta#2023)
- fix: `cargo install git-delta --locked` fails on systems with GCC 15 by [@&#8203;tquin](https://github.com/tquin) in [#&#8203;2007](dandavison/delta#2007)
- Normalize `merge.conflictStyle` casing by [@&#8203;injust](https://github.com/injust) in [#&#8203;2015](dandavison/delta#2015)
- Styled zero lines fix by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;1916](dandavison/delta#1916)
- config: add setup instructions for Jujutsu (jj) vcs by [@&#8203;arjunmahishi](https://github.com/arjunmahishi) in [#&#8203;2048](dandavison/delta#2048)
- all: fix clippy complaints by [@&#8203;charlievieth](https://github.com/charlievieth) in [#&#8203;2038](dandavison/delta#2038)
- Cache the Git remote URL to speed up rendering hyperlinks by [@&#8203;charlievieth](https://github.com/charlievieth) in [#&#8203;1940](dandavison/delta#1940)
- deps: update cc by [@&#8203;ognevny](https://github.com/ognevny) in [#&#8203;2053](dandavison/delta#2053)
- rg json handling: fix line comment highlighting by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;2057](dandavison/delta#2057)
- Update dirs dependency to version 6 by [@&#8203;musicinmybrain](https://github.com/musicinmybrain) in [#&#8203;2063](dandavison/delta#2063)
- default line number to 1 for hyperlinks by [@&#8203;schpet](https://github.com/schpet) in [#&#8203;2061](dandavison/delta#2061)
- Fix line numbers showing filename when hyperlinks enabled by [@&#8203;tsvikas](https://github.com/tsvikas) in [#&#8203;2058](dandavison/delta#2058)
- less hist file: look at xdg paths by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;2065](dandavison/delta#2065)
- CI: remove x86 apple/macOS by [@&#8203;th1000s](https://github.com/th1000s) in [#&#8203;2074](dandavison/delta#2074)
- Update bat dependency from 0.24 to 0.26 by [@&#8203;dandavison](https://github.com/dandavison) in [#&#8203;2115](dandavison/delta#2115)

#### New Contributors

- [@&#8203;dvermd](https://github.com/dvermd) made their first contribution in [#&#8203;1856](dandavison/delta#1856)
- [@&#8203;lvdh](https://github.com/lvdh) made their first contribution in [#&#8203;1864](dandavison/delta#1864)
- [@&#8203;sharma-shray](https://github.com/sharma-shray) made their first contribution in [#&#8203;1892](dandavison/delta#1892)
- [@&#8203;harmtemolder](https://github.com/harmtemolder) made their first contribution in [#&#8203;1896](dandavison/delta#1896)
- [@&#8203;ernstki](https://github.com/ernstki) made their first contribution in [#&#8203;1941](dandavison/delta#1941)
- [@&#8203;tquin](https://github.com/tquin) made their first contribution in [#&#8203;2007](dandavison/delta#2007)
- [@&#8203;arjunmahishi](https://github.com/arjunmahishi) made their first contribution in [#&#8203;2048](dandavison/delta#2048)
- [@&#8203;charlievieth](https://github.com/charlievieth) made their first contribution in [#&#8203;2038](dandavison/delta#2038)
- [@&#8203;ognevny](https://github.com/ognevny) made their first contribution in [#&#8203;2053](dandavison/delta#2053)
- [@&#8203;musicinmybrain](https://github.com/musicinmybrain) made their first contribution in [#&#8203;2063](dandavison/delta#2063)
- [@&#8203;schpet](https://github.com/schpet) made their first contribution in [#&#8203;2061](dandavison/delta#2061)
- [@&#8203;tsvikas](https://github.com/tsvikas) made their first contribution in [#&#8203;2058](dandavison/delta#2058)

**Full Changelog**: <dandavison/delta@0.18.2...0.19.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My44OS42IiwidXBkYXRlZEluVmVyIjoiNDMuODkuNiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90IiwiYXV0b21hdGlvbjpib3QtYXV0aG9yZWQiLCJkZXBlbmRlbmN5LXR5cGU6Om1pbm9yIl19-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Hyperlinks make delta 55x slower when used as the pager for git log

3 participants