<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello,</p>
    <p>happy to help.</p>
    <p>Apologies in advance for the longer email.</p>
    <p>I was measuring the line-by-line performance of summary page.
      Measurements provided below contain only main culprit lines above
      10 ms.</p>
    <p>Summary page:<span style="font-family:monospace"><br>
      </span>
      <span style="font-family:monospace"><br>
        <span style="color:#000000;background-color:#ffffff;">Total
          time: 6.7141 s</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">File:
          Kallithea/kallithea/controllers/summary.py</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">Function:
          SummaryController.index at line 116</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">Line #
               Hits         Time  Per Hit   % Time  Line Contents</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">==============================================================<br>
        </span>...<br>
        <span style="color:#000000;background-color:#ffffff;">  123
                  1       2422.3   2422.3     36.1
                       collection =
          c.db_repo_scm_instance.get_changesets(reverse=True)<br>
        </span>...<br>
        <span style="color:#000000;background-color:#ffffff;">  127
                  1       1167.4   1167.4     17.4
                   c.cs_pagination = Page(collection, page=p,
          items_per_page=size)<br>
          ...</span><br>
        <span style="color:#000000;background-color:#ffffff;">   167
                  1       3101.2   3101.2     46.2          return
          base.render('summary/summary.html')</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
      </span><br>
      from that I drilled down to get_changesets:</p>
    <p><span style="font-family:monospace"><span
          style="color:#000000;background-color:#ffffff;">Total time:
          2.38587 s</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">File:
          Kallithea/kallithea/lib/vcs/backends/git/repository.py</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">Function:
          GitRepository.get_changesets at line 554</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">Line #
               Hits         Time  Per Hit   % Time  Line Contents</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">==============================================================<br>
        </span>...<br>
        <span style="color:#000000;background-color:#ffffff;">  583
                  1       1175.0   1175.0     49.2          if
          self._empty:<br>
        </span>...<br>
        <span style="color:#000000;background-color:#ffffff;">   600
                  1       1210.6   1210.6     50.7          revs =
          self.run_git_command(cmd).splitlines()<br>
          ...</span></span></p>
    <p>through _empty:</p>
    <p>
      <span style="font-family:monospace"><span
          style="color:#000000;background-color:#ffffff;">Total time:
          1.17289 s</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">File:
          Kallithea/kallithea/lib/vcs/backends/git/repository.py</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">Function:
          GitRepository._empty at line 104</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">Line #
               Hits         Time  Per Hit   % Time  Line Contents</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">==============================================================<br>
        </span>...<br>
        <span style="color:#000000;background-color:#ffffff;">   111
                  1       1172.9   1172.9    100.0
                       self.revisions[0]<br>
          ...</span></span></p>
    <p>and through _get_all_revisions:</p>
    <p>
      <span style="font-family:monospace"><span
          style="color:#000000;background-color:#ffffff;">Total time:
          1.17006 s</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">File:
          Kallithea/kallithea/lib/vcs/backends/git/repository.py</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">Function:
          GitRepository._get_all_revisions at line 310</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">Line #
               Hits         Time  Per Hit   % Time  Line Contents</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">==============================================================<br>
        </span>...<br>
        <span style="color:#000000;background-color:#ffffff;">   323
                  1       1168.3   1168.3     99.8              so =
          self.run_git_command(cmd)<br>
          ...</span></span></p>
    <p>into _run_git_command:</p>
    <p>
      <span style="font-family:monospace"><span
          style="color:#000000;background-color:#ffffff;">Total time:
          1.16255 s</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">File:
          Kallithea/kallithea/lib/vcs/backends/git/repository.py</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">Function:
          GitRepository._run_git_command at line 125</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">Line #
               Hits         Time  Per Hit   % Time  Line Contents</span><span
          style="color:#000000;background-color:#ffffff;">
        </span><br>
        <span style="color:#000000;background-color:#ffffff;">==============================================================<br>
        </span>...<br>
        <span style="color:#000000;background-color:#ffffff;">   143
                  1       1141.9   1141.9     98.2              p =
          subprocessio.SubprocessIOChunker(cmd, cwd=cwd, env=gitenv,
          shell=False)<br>
          ...</span></span></p>
    <p>From bottom to top:</p>
    <ol>
      <li>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).</li>
      <li>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.</li>
      <li>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.</li>
      <li>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.</li>
      <li>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.</li>
    </ol>
    <p>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. <br>
      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.<br>
      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.</p>
    <p>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.</p>
    <p>Best regards.</p>
    <p>Tomas</p>
    <div class="moz-cite-prefix">Dne 26. 11. 26 v 1:52 Mads Kiilerich
      napsal(a):<br>
    </div>
    <blockquote type="cite"
      cite="mid:3cbe7a0d-4635-495d-8534-776a1da4d541@kiilerich.com">Thanks.
      <br>
      <br>
      I finally got around to look at this. I pushed part of the changes
      to the stable branch.
      <br>
      <br>
      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?
      <br>
      <br>
      /Mads
      <br>
      <br>
      <br>
      On 24/04/2026 13:44, Tomáš Musil wrote:
      <br>
      <blockquote type="cite">Hello,
        <br>
        <br>
        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.
        <br>
        <br>
        I have tracked down the issues to:
        <br>
        <br>
        1. _empty() loads all revisions but just checking if repo has
        "head" seems to do the trick
        <br>
        2. _heads() loads and iterates over all refs (including tags)
        but later only checks /refs/heads and /refs/remotes/origin
        <br>
        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
        <br>
        <br>
        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.
        <br>
        <br>
        Overall these changes dropped summary loading time to <2sec
        and changelog to <3sec for our large repo.
        <br>
        <br>
        Thank you for keeping the Kallithea project alive.
        <br>
        <br>
        Best regards,
        <br>
        <br>
        Tomas
        <br>
        <br>
        _______________________________________________
        <br>
        kallithea-general mailing list
        <br>
        <a class="moz-txt-link-abbreviated" href="mailto:kallithea-general@sfconservancy.org">kallithea-general@sfconservancy.org</a>
        <br>
<a class="moz-txt-link-freetext" href="https://lists.sfconservancy.org/mailman/listinfo/kallithea-general">https://lists.sfconservancy.org/mailman/listinfo/kallithea-general</a>
        <br>
      </blockquote>
      <br>
    </blockquote>
    <div class="moz-signature">-- <br>
      <span style="color: black; font-family: Calibri">
        <table text-align:"left"="" align:"right"=""
          style="width:300px; border:0px">
          <tbody>
            <tr>
              <td style="width:100%">
                <b>Tomáš Musil <br>
                  ATM System Development Manager </b> <br>
                <a href="mailto: tomas.musil@atrak.cz"
                  class="moz-txt-link-freetext">tomas.musil@atrak.cz</a>
                <br>
                +420 702 170 712 <br>
                <br>
                <img src="cid:part1.Qu95g9zA.0CS0KTeK@atrak.cz"
                  align="right" valign="bottom">
                <b> ATRAK a.s. </b> <br>
                Aviaticka 1039/6 <br>
                161 00 Prague 6 <br>
                Czech Republic <br>
                <a href="http://www.atrak.cz">www.atrak.cz</a> <br>
              </td>
            </tr>
          </tbody>
        </table>
        <br>
        <br>
        <br>
      </span></div>
  </body>
</html>