[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

Đang mở
#5,267 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp, git
Lĩnh vực
cli, performance

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).

Ngôn ngữ chính
C#
Star
3.1k
Fork
661
Merge trung bình
7 giờ 4 phút
Pull request đã merge (30 ngày)
77

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của GitTools/GitVersion

Tất cả issue của GitTools/GitVersion

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.