[PATCH] git: improve changelog and summary performance for large repos
Tomáš Musil
tomas.musil at atrak.cz
Fri Nov 27 11:07:41 UTC 2026
Your changes work for me and from a quick test they seem to be even
faster than my solution. Repository summary page is <1s and changelog
page is ~1.5s
Great find.
Tomas
Dne 26. 11. 26 v 23:19 Mads Kiilerich napsal(a):
> Thanks for the thorough analysis.
>
> I think I found the root cause for the issues I saw - it might be
> fixed in the attached patches. Does that work for you too?
>
> But also, folder browsing should probably just use changeset_cache
> from the database, without touching the actual repository ...
>
> /Mads
>
>
> On 26/11/2026 19:22, Tomáš Musil wrote:
>>
>> Hello,
>>
>> happy to help.
>>
>> Apologies in advance for the longer email.
>>
>> I was measuring the line-by-line performance of summary page.
>> Measurements provided below contain only main culprit lines above 10 ms.
>>
>> Summary page:
>>
>> Total time: 6.7141 s
>> File: Kallithea/kallithea/controllers/summary.py
>> Function: SummaryController.index at line 116
>>
>> Line # Hits Time Per Hit % Time Line Contents
>> ==============================================================
>> ...
>> 123 1 2422.3 2422.3 36.1
>> collection =
>> c.db_repo_scm_instance.get_changesets(reverse=True)
>> ...
>> 127 1 1167.4 1167.4 17.4
>> c.cs_pagination = Page(collection, page=p, items_per_page=size)
>> ...
>> 167 1 3101.2 3101.2 46.2 return
>> base.render('summary/summary.html')
>>
>> from that I drilled down to get_changesets:
>>
>> Total time: 2.38587 s
>> File: Kallithea/kallithea/lib/vcs/backends/git/repository.py
>> Function: GitRepository.get_changesets at line 554
>>
>> Line # Hits Time Per Hit % Time Line Contents
>> ==============================================================
>> ...
>> 583 1 1175.0 1175.0 49.2 if self._empty:
>> ...
>> 600 1 1210.6 1210.6 50.7 revs =
>> self.run_git_command(cmd).splitlines()
>> ...
>>
>> through _empty:
>>
>> Total time: 1.17289 s
>> File: Kallithea/kallithea/lib/vcs/backends/git/repository.py
>> Function: GitRepository._empty at line 104
>>
>> Line # Hits Time Per Hit % Time Line Contents
>> ==============================================================
>> ...
>> 111 1 1172.9 1172.9 100.0
>> self.revisions[0]
>> ...
>>
>> and through _get_all_revisions:
>>
>> Total time: 1.17006 s
>> File: Kallithea/kallithea/lib/vcs/backends/git/repository.py
>> Function: GitRepository._get_all_revisions at line 310
>>
>> Line # Hits Time Per Hit % Time Line Contents
>> ==============================================================
>> ...
>> 323 1 1168.3 1168.3 99.8 so =
>> self.run_git_command(cmd)
>> ...
>>
>> into _run_git_command:
>>
>> Total time: 1.16255 s
>> File: Kallithea/kallithea/lib/vcs/backends/git/repository.py
>> Function: GitRepository._run_git_command at line 125
>>
>> Line # Hits Time Per Hit % Time Line Contents
>> ==============================================================
>> ...
>> 143 1 1141.9 1141.9 98.2 p =
>> subprocessio.SubprocessIOChunker(cmd, cwd=cwd, env=gitenv, shell=False)
>> ...
>>
>> From bottom to top:
>>
>> 1. mutliplying the default buffer_size and chunk_size
>> in SubprocessIOChunker reduced this particular execution from
>> 1141ms to 169ms. (Note again: I don't really understand the
>> implications of this change so this is not my proposed solution).
>> 2. as you've mentioned, the self.revisions is cached (for a single
>> summary page display the _empty method is called 21 times but
>> _get_all_revisions only once) but only for the duration of a
>> single request, so reloading the page retriggers the calculation.
>> 3. Even after the change in point 1 the first call of _empty still
>> takes around 181ms, replacing the check for self.revisions with
>> checking self.head lowers it to 0.2ms, though this call is not
>> cached.
>> 4. These changes lower the execution of get_changesets to 200ms from
>> initial 2422ms, where the main culprit remains the
>> run_git_command at line 600.
>> 5. The overall SummaryController.index then takes about 2 seconds,
>> where the most time remains in pagination on line 127 which I
>> didn't manage to optimize. The rendering of summary page also
>> seemingly went down to about 400ms, probably due to subsequent
>> running of other git commands outside of the get_changesets.
>>
>> My logic behind the _empty change was that it's unnecessary to load
>> all revisions just to check if there is any, so checking the head
>> seemed fine to me.
>> I've looked at the tests and I think the issue is that self.head
>> checks for refs[b'HEAD'] but the GitInMemoryChangeset used for test
>> repo preparation never sets that ref.
>> With that said, I don't have enough knowledge to claim that the issue
>> is in the tests rather than in my assumption that every non-empty
>> repo has HEAD set, so I leave that up to you.
>>
>> Equivalent analysis was applied to the changelog page, where the
>> issue was simply that calling _heads for each of the 100 changesets
>> on the page iterated over all refs in the repo (including the 4k tags
>> in my case) unnecessarily.
>>
>> Best regards.
>>
>> Tomas
>>
>> Dne 26. 11. 26 v 1:52 Mads Kiilerich napsal(a):
>>> Thanks.
>>>
>>> I finally got around to look at this. I pushed part of the changes
>>> to the stable branch.
>>>
>>> I do however see problems with the _empty fixes: They cause test
>>> failures. I have not investigated why. Also, self.revisions is
>>> cached and should not be recomputed that often. Can you clarify the
>>> exact code path and problem you see?
>>>
>>> /Mads
>>>
>>>
>>> On 24/04/2026 13:44, Tomáš Musil wrote:
>>>> Hello,
>>>>
>>>> we have recently converted a large repo (22k revisions, 4k tags)
>>>> from Mercurial to Git and noticed a major slowdown when loading
>>>> summary (8 seconds) and changelog (24 seconds) pages, when for
>>>> Mercurial repo the pages show basically instantly.
>>>>
>>>> I have tracked down the issues to:
>>>>
>>>> 1. _empty() loads all revisions but just checking if repo has
>>>> "head" seems to do the trick
>>>> 2. _heads() loads and iterates over all refs (including tags) but
>>>> later only checks /refs/heads and /refs/remotes/origin
>>>> 3. SubprocessIOChunker's default buffer_size and chunk_size seem to
>>>> be pretty low in _run_git_command when running "git log" to get all
>>>> revisions
>>>>
>>>> I attempted to address the first two points in the attached patch,
>>>> in the third point I just mutiplied the defaults by 100 which seems
>>>> to be enough for our repo but definitely is not a properly
>>>> calculated solution.
>>>>
>>>> Overall these changes dropped summary loading time to <2sec and
>>>> changelog to <3sec for our large repo.
>>>>
>>>> Thank you for keeping the Kallithea project alive.
>>>>
>>>> Best regards,
>>>>
>>>> Tomas
>>>>
>>>> _______________________________________________
>>>> kallithea-general mailing list
>>>> kallithea-general at sfconservancy.org
>>>> https://lists.sfconservancy.org/mailman/listinfo/kallithea-general
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sfconservancy.org/pipermail/kallithea-general/attachments/20261127/046e82bd/attachment.html>
More information about the kallithea-general
mailing list