<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>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</p>
    <p>Great find.</p>
    <p>Tomas</p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">Dne 26. 11. 26 v 23:19 Mads Kiilerich
      napsal(a):<br>
    </div>
    <blockquote type="cite"
      cite="mid:51c8508c-638c-4329-b3d6-36cf31f81351@kiilerich.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <div class="moz-cite-prefix">Thanks for the thorough analysis.</div>
      <div class="moz-cite-prefix"><br>
      </div>
      <div class="moz-cite-prefix">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?</div>
      <div class="moz-cite-prefix"><br>
      </div>
      <div class="moz-cite-prefix">But also, folder browsing should
        probably just use changeset_cache from the database, without
        touching the actual repository ...</div>
      <div class="moz-cite-prefix"><br>
      </div>
      <div class="moz-cite-prefix">/Mads</div>
      <div class="moz-cite-prefix"><br>
      </div>
      <div class="moz-cite-prefix"><br>
      </div>
      <div class="moz-cite-prefix">On 26/11/2026 19:22, Tomáš Musil
        wrote:<br>
      </div>
      <blockquote type="cite"
        cite="mid:ed05b8a1-f4a6-455f-8237-e545ff78d6ab@atrak.cz">
        <meta http-equiv="Content-Type"
          content="text/html; charset=UTF-8">
        <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="">Total time: 6.7141 s</span><span style=""> </span><br>
            <span style="">File:
              Kallithea/kallithea/controllers/summary.py</span><span
              style=""> </span><br>
            <span style="">Function: SummaryController.index at line 116</span><span
              style=""> </span><br>
            <span style=""> </span><br>
            <span style="">Line #      Hits         Time  Per Hit   %
              Time  Line Contents</span><span style=""> </span><br>
            <span style="">==============================================================<br>
            </span>...<br>
            <span style="">  123         1       2422.3   2422.3
                  36.1              collection =
              c.db_repo_scm_instance.get_changesets(reverse=True)<br>
            </span>...<br>
            <span style="">  127         1       1167.4   1167.4
                  17.4          c.cs_pagination = Page(collection,
              page=p, items_per_page=size)<br>
              ...</span><br>
            <span style="">   167         1       3101.2   3101.2
                  46.2          return
              base.render('summary/summary.html')</span><span style="">
            </span><br>
          </span><br>
          from that I drilled down to get_changesets:</p>
        <p><span style="font-family:monospace"><span style="">Total
              time: 2.38587 s</span><span style=""> </span><br>
            <span style="">File:
              Kallithea/kallithea/lib/vcs/backends/git/repository.py</span><span
              style=""> </span><br>
            <span style="">Function: GitRepository.get_changesets at
              line 554</span><span style=""> </span><br>
            <span style=""> </span><br>
            <span style="">Line #      Hits         Time  Per Hit   %
              Time  Line Contents</span><span style=""> </span><br>
            <span style="">==============================================================<br>
            </span>...<br>
            <span style="">  583         1       1175.0   1175.0
                  49.2          if self._empty:<br>
            </span>...<br>
            <span style="">   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="">Total
              time: 1.17289 s</span><span style=""> </span><br>
            <span style="">File:
              Kallithea/kallithea/lib/vcs/backends/git/repository.py</span><span
              style=""> </span><br>
            <span style="">Function: GitRepository._empty at line 104</span><span
              style=""> </span><br>
            <span style=""> </span><br>
            <span style="">Line #      Hits         Time  Per Hit   %
              Time  Line Contents</span><span style=""> </span><br>
            <span style="">==============================================================<br>
            </span>...<br>
            <span style="">   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="">Total
              time: 1.17006 s</span><span style=""> </span><br>
            <span style="">File:
              Kallithea/kallithea/lib/vcs/backends/git/repository.py</span><span
              style=""> </span><br>
            <span style="">Function: GitRepository._get_all_revisions at
              line 310</span><span style=""> </span><br>
            <span style=""> </span><br>
            <span style="">Line #      Hits         Time  Per Hit   %
              Time  Line Contents</span><span style=""> </span><br>
            <span style="">==============================================================<br>
            </span>...<br>
            <span style="">   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="">Total
              time: 1.16255 s</span><span style=""> </span><br>
            <span style="">File:
              Kallithea/kallithea/lib/vcs/backends/git/repository.py</span><span
              style=""> </span><br>
            <span style="">Function: GitRepository._run_git_command at
              line 125</span><span style=""> </span><br>
            <span style=""> </span><br>
            <span style="">Line #      Hits         Time  Per Hit   %
              Time  Line Contents</span><span style=""> </span><br>
            <span style="">==============================================================<br>
            </span>...<br>
            <span style="">   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 moz-txt-link-freetext"
              href="mailto:kallithea-general@sfconservancy.org"
              moz-do-not-send="true">kallithea-general@sfconservancy.org</a>
            <br>
            <a class="moz-txt-link-freetext"
href="https://lists.sfconservancy.org/mailman/listinfo/kallithea-general"
              moz-do-not-send="true">https://lists.sfconservancy.org/mailman/listinfo/kallithea-general</a>
          </blockquote>
        </blockquote>
      </blockquote>
    </blockquote>
  </body>
</html>