[ISSUE]: 6.7.0 spends ~7s per candidate in "Finding branches source" (~9 min total) on repos with many branches, and every candidate is then skipped as orphaned

Abierto
#5,267 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
csharp, git
Área
cli, performance

Línea de trabajo

Start at the version-calculation path that logs “Fetching the base versions for version calculation” and “Finding branches source,” focusing on candidate branches and the source-branches configuration. Compare the unknown configuration with source-branches: [main] using a repository with many remote branches. Done means equivalent FullSemVer, BranchName, and Sha output without the excessive per-candidate delay.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug
Prerequisites
  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported
GitVersion package

GitVersion.Tool

GitVersion version

6.7.0 (6.7.0+Branch.main.Sha.00e59b5f45fe97e2e610a480a860b3a009db9602)

Operating system

Linux

What are you seeing?

On a TeamCity agent that fetches all heads (teamcity.git.fetchAllHeads=true), version calculation takes 8.5–9+ minutes on every non-main build. Almost all of that time is spent inside Fetching the base versions for version calculation, in one Finding branches source of '<branch>' block per candidate source branch.

In one diagnostic run of a build for a branch that matches the unknown config:

Metric | Value -- | -- Remote branches | ~825 (normalization turns each into a local branch too) Commits reachable from HEAD | ~42,000 Tags | ~680 Finding branches source blocks | 81 Time per block | 6.8 to 11.7 s, every block took over 1 s Total time in those blocks | ~583 s Total time in the Finding merge base calls nested inside them (95 calls) | ~4.9 s Candidates then reported as An orphaned branch '...' has been detected and will be skipped=True. | 79 of 81

Things that stand out:

  1. The cost is not the merge-base work. The nested merge-base lookups take milliseconds. For example, merge-requests/5735/head spends 6.8 s between Begin: Finding branches source and its only Finding merge base call, which takes 1.81 ms. Nearly all of the ~7 s per candidate happens before any merge base is computed. It looks like each candidate triggers a scan over all ~1,650 local and remote refs, or over the full history.
  2. Every candidate is evaluated twice, once as the local branch created by normalization and once as origin/<same branch>. For example, feature/X and origin/feature/X take ~9.5 s each.
  3. Almost all of that work is thrown away. 79 of 81 candidates (all feature/* and pull-request branches) end up skipped as "orphaned". The version comes from main either way.
  4. The time grows linearly with the number of feature/* and pull-request branches on the remote, so builds get slower as the branch count grows.

Setting source-branches: [main] on the unknown and pull-request configs brings it down to ~25–40 s with identical output (FullSemVer, BranchName, Sha, and so on). So the expensive work does not change the result here.

The same slowdown affects pull-request builds (merge-requests/<n>/head, GitLab refs on TeamCity): 8.5–9 min with the default pull-request source branches, and 25–35 s with source-branches: [main], same version.

What is expected?
  • Checking a candidate source branch should cost roughly what its merge base costs (milliseconds), not ~7 s.
  • A branch and its remote-tracking twin (feature/X and origin/feature/X) should be evaluated once, not twice.
  • Ideally, candidates that will end up discarded as orphaned should be detected cheaply before the expensive part.

A 42k-commit repository with ~800 branches should compute a version in seconds on a build server, the same as it does with source-branches: [main].

Steps to Reproduce

A repository with ~42k commits on master, ~680 tags and ~825 remote branches. Of those, ~33 match the default feature regex, ~7 are merge-requests//head, and the rest (~785) match the unknown config.
GitVersion.yml:

branches:
  main:
    regex: ^master$|^main$
    mode: ContinuousDelivery
    label: ci
  feature:
    mode: ContinuousDelivery
  pull-request:
    regex: ^(pull|pull\-requests|pr|merge|merge\-requests)[/-](?<PRNumber>\d+)
    mode: ContinuousDelivery
    label: PullRequest{PRNumber}
ignore:
  sha: []

A build-server checkout with all heads fetched and a single origin remote. Environment: TEAMCITY_VERSION set, Git_Branch=refs/heads/ (a branch matching unknown, e.g. renovate/patch-nodejs-packages), HEAD detached at that branch's tip.
Run:
dotnet-gitversion -nocache -nofetch -verbosity Diagnostic -l gitversion.log
Observe ~81 Finding branches source blocks at ~7 s each, and the orphaned ... skipped=True lines after them.

Workaround that brings it to ~30 s with identical output:


  pull-request:
    # ...
    source-branches:
    - main
  unknown:
    source-branches:
    - main

Environment for the numbers above: Linux x64 (kernel 6.8), .NET SDK 10.0.401. The TeamCity agents (Linux) show the same timings: SetVersionInfo 9m05s–9m13s with the defaults, 35 s with the workaround.

RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).

Lenguaje dominante
C#
Estrellas
3.1k
Forks
661
Merge medio
7 h 4 min
PR fusionados (30 d)
77

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de GitTools/GitVersion

Todos los issues de GitTools/GitVersion

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.