Backport of 'Fix quadratic line reading in CI trace reverse scan' (19.2)

What does this MR do and why?

This is an N-1 backport for GitLab Dedicated, which runs 19.2 and cannot upgrade to 19.3 for several weeks. It needs release manager agreement to merge into 19-2-stable-ee. It is part of the fix set tracked in https://gitlab.com/gitlab-org/gitlab/-/work_items/605350 (Ci::BuildFinishedWorker latency) and #597765 (severity::2, actively paging a Dedicated tenant).

Backports !244683 (merged), merged and deployed to GitLab.com on 2026-07-14. No feature flag is involved.

Gitlab::Ci::Trace::Stream#reverse_line re-copied the entire accumulated buffer on every 4KB step while scanning backwards. This is quadratic in the length of any segment with no newlines, such as \r progress bars or base64-encoded dumps. Measured against real traces: 0.85s to scan an 8MB segment, 17.3s at 32MB, and roughly 70s extrapolated at 64MB.

The fix accumulates chunks and joins them once per newline flush, making the scan linear instead: 8ms at 32MB.

Coverage extraction runs this reverse scan synchronously for every finished build that has a coverage_regex configured, inside Ci::BuildFinishedWorker. This was the source of the highest cpu_s cases identified in the latency investigation.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

  • This MR is backporting a bug fix, documentation update, or spec fix, previously merged in the default branch.
  • The MR that fixed the bug on the default branch has been deployed to GitLab.com (not applicable for documentation or spec changes).
  • The MR title is descriptive (e.g. "Backport of 'title of default branch MR'"). This is important, since the title will be copied to the patch blog post.
  • Required labels have been applied to this merge request
  • This MR has been approved by a maintainer (only one approval is required).
  • Ensure the e2e:test-on-omnibus-ee job has succeeded, or if it has failed, investigate the failures. If you determine the failures are unrelated, you may proceed. If you need assistance investigating, request help in the #s_developer_experience Slack channel to confirm the failures are unrelated to the merge request.

Note to the merge request author and maintainer

If you have questions about the patch release process, please:

Edited by Hordur Freyr Yngvason

Merge request reports

Loading
Loading