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

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

Open
charlievieth opened this issue Jan 11, 2025 · 1 comment · May be fixed by #1940
Open

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

charlievieth opened this issue Jan 11, 2025 · 1 comment · May be fixed by #1940

Comments

@charlievieth
Copy link

charlievieth commented Jan 11, 2025

Issue

The hyperlinks option makes delta ~55x slower when used as the pager for git log because it calls GitConfig::get_remote_url for each commit hash, which is incredibly slow and essentially makes delta unusable for repos with many commits.

Possible Solution

If possible, delta should cache the Git remote URL and re-use it. I would create a PR that does this, but my Rust skills are extremely limited (though I may still try).

Performance tests

Both of these commands were ran from the root of a recent version of the Linux source tree. The below results are from an M4 Mac Pro, but were roughly equal to the results I got on my AMD Linux server. We limit the amount of git log data processed to 32MiB (head -c $((32 * 1024 * 1024))) since processing the full output of git log when hyperlinks are enabled takes an very very long time (when processing the full amount the slow down is 66x, which I would consider more accurate because it amortizes the startup time).

Note: A recent version of pv is required to run the below commands since the --stats option is a recent addition. Homebrew will install the latest version, but if you're on a Linux distro that does not have a recent version then it can easily be built from source (you'll need to run autoreconf --force --install --verbose -Wall to generate the configure file if building from the Git repo).

Hyperlinks Enabled

# cd to a repo with a large commit history then run:
$ DELTA_PAGER='bash -c "time head -c $((32 * 1024 * 1024)) | pv --stats --output=/dev/null"' \
    git -c 'pager.log=delta --hyperlinks' log
    
32.0MiB 0:00:43 [ 755KiB/s]
rate min/avg/max/mdev = 731516.382/773784.852/814642.291/16590.908 B/s

real	0m43.400s
user	0m0.183s
sys	0m1.367s

Hyperlinks Disabled

# cd to a repo with a large commit history then run:
$ DELTA_PAGER='bash -c "time head -c $((32 * 1024 * 1024)) | pv --stats --output=/dev/null"' \
    git -c 'pager.log=delta' log
    
32.0MiB 0:00:00 [40.1MiB/s]
rate min/avg/max/mdev = 42006890.474/42006890.474/42006890.474/nan B/s

real	0m0.802s
user	0m0.051s
sys	0m0.379s

CPU Profiles (macOS Instruments) with Hyperlinks

Call Tree

Screenshot 2025-01-10 at 6 51 55 PM

Flamegraph

Screenshot 2025-01-10 at 6 54 15 PM

CPU Profile without Hyperlinks

When hyperlinks are disabled we see that delta spends most of its time writing to stdout, which I'd expect since we're writing more data than we've read (since we're adding escape sequences and write(2) is pretty slow on macOS) and consuming input (processing ANSI input):

Screenshot 2025-01-10 at 7 59 10 PM
@charlievieth charlievieth changed the title 🐛 The hyperlinks option makes delta 55x slower when used as the pager for git log 🐛 Hyperlinks make delta 55x slower when used as the pager for git log Jan 11, 2025
charlievieth added a commit to charlievieth/delta that referenced this issue Jan 11, 2025
This commit speeds up the rendering of hyperlinks by ~55x by caching the
Git repo's remote URL instead of fetching it each time a hyperlink is
rendered.

Fixes dandavison#1939
@dandavison
Copy link
Owner

Thanks very much for creating such a helpful report on this issue @charlievieth!

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 a pull request may close this issue.

2 participants