delta: πŸ› delta `0.12.0` is slower than `0.11.3`

Hi! I see something similar to #824 (which is fixed in 0.11.2). I will try to reproduce it in docker and post the output.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

@dandavison I notice it when running git diff. My git pager is defined like this:

[core]
	pager = "delta 2> /dev/null || { { { diff-so-fancy || cat ; } 2> /dev/null ; } | less --tabs=4 -RFX -- ; }"

The expression is complex because I want it to have a fall back if delta is not installed.

Oops, I can actually reproduce it in docker, I just misread the output. The behavior is similar to #824: it’s slow with many processes running. Here’s the full script I used:

build_oci_img () {
  # RUN apk add --no-cache bash git
  docker build "$@" - <<'EOF'
  FROM archlinux
  RUN pacman -Sy > /dev/null
  RUN pacman -S --noconfirm --needed coreutils curl gcc bc git > /dev/null
  ENV CARGO_HOME=/usr/local
  RUN curl -fsSL 'https://sh.rustup.rs' | sh -s -- -y --profile minimal
  RUN /usr/local/bin/cargo install --version 0.11.3 git-delta && cp /usr/local/bin/delta /usr/local/bin/delta-0.11.3
  RUN /usr/local/bin/cargo install --version 0.12.0 git-delta && cp /usr/local/bin/delta /usr/local/bin/delta-0.12.0
  WORKDIR /repo
EOF
}

build_oci_img
docker run --rm -i "$(build_oci_img -q)" bash <<'EOF'
benchmark-command() {
  local num_runs="${1:-100}"
  shift
  local before
  before=$(($(date +%s%N) / 1000000))
  printf 'Running command "%s" %d times\n' "$*" "${num_runs}"
  for _ in $(seq 1 "${num_runs}"); do
    eval -- "$@" > /dev/null
  done
  local after
  after=$(($(date +%s%N) / 1000000))
  local per_run
  per_run=$(bc < <(printf 'scale=2; %d/%d\n' $((after - before)) "${num_runs}"))
  echo "${per_run} ms per run ($((after - before)) ms total)"
}

benchmark-delta-versions() {
  for v in 0.11.3 0.12.0; do
    echo "Benchmarking version: $v"
    delta-${v} --version
    benchmark-command 10 "git diff --no-index a b | delta-${v} >| delta-${v}-result"
  done
}

main() {
  echo aaa > a
  echo aab > b
  git diff --no-index a b | delta
  benchmark-delta-versions
  echo "Spinning up 5000 processes"
  for i in {1..5000}; do
    nohup sleep 30 & &> /dev/null
  done
  echo "Process counts:"
  ps --no-headers -e -o fname | sort | uniq -c
  benchmark-delta-versions
}

main
EOF

Which results in:

Spinning up 5000 processes
Process counts:
      1 bash
      1 ps
   5000 sleep
      1 sort
      1 uniq
Benchmarking version: 0.11.3
delta 0.11.3
Running command "git diff --no-index a b | delta-0.11.3 >| delta-0.11.3-result" 10 times
76.70 ms per run (767 ms total)
Benchmarking version: 0.12.0
delta 0.12.0
Running command "git diff --no-index a b | delta-0.12.0 >| delta-0.12.0-result" 10 times
419.70 ms per run (4197 ms total)

Fixed by #984 (and released)

Is it possible to opt out from querying the processes?

It’s not currently, but I’d like to carry on improving this situation. For now, @infokiller, I’m assuming you have a workaround for your personal work? E.g. something like 2db5463.

My current workaround is to install 0.11.3 using cargo install --version 0.11.3 --locked --all-features