Search code examples
cgitperformancelibgit2

In what scenarios libgit2 is faster than git?


I can write a Zsh module with some subset of git-command features. The motivation is to accelerate prompts. Example prompt that I use does:

    changed_files=()
    git diff --quiet 2> /dev/null || changed_files=(${(f)"$( git diff --name-only 2>/dev/null )"})

This is not very fast when entering e.g. linux-kernel repo. I wonder if libgit2 could give more control over some typical tasks, and be faster this or other way.

I guess chances are low, because Git repository has simple structure, so git code is 1-to-1 reflection of it. But who knows? Any distinct libgit2 performance trait is in my interest.


Solution

  • The typical scenario is when you have multiple chained git calls, each one having to open a shell/process.

    But in 2017, most of the tools using libgit2 are starting to go back to a wrapping approach (wrapping git calls instead of relying on libgit2): Example Visual Studio 15.

    Git itself continues to evolve regularly and fixes bugs or introduces new features, and they are not always present in libgit2 (as in this example).

    In your case, for basic chained git functions, a C program calling libgit2 might be faster, but you need to measure it.