Reduce stage log Put allocation overhead in filestore persistence

Đang mở
#7,026 1 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 2 ngày

@manenim đang làm issue này rồi.

Từ ngày 18/10/2026.

  • #7027 của @rootp1 — đã đóng, không merge

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
58/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
go
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu tại pkg/app/server/stagelogstore/filestore.go, đọc stageLogFileStore.Put quanh các dòng 65-82 và TODO về hiệu năng của nó. Thêm benchmark tập trung được mô tả trong issue cho lf.Blocks tăng dần, sau đó so sánh số lượng cấp phát và chi phí ghi trong khi kiểm tra hành vi đọc hiện có. Được coi là hoàn tất khi có cải thiện đo lường được, định dạng phân tách theo dòng và EOL marker được giữ nguyên, đồng thời không có thay đổi hành vi không liên quan.

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

Mô tả

What happened:

Summary

stageLogFileStore.Put rewrites the entire stage-log fragment on every save by JSON-encoding each LogBlock into a fresh in-memory buffer and then writing the full byte slice to the filestore. The code already carries a TODO for this hot path, and the current implementation scales allocations and latency with total block count on every write.

Affected Area

  • pkg/app/server/stagelogstore/filestore.go
  • stage log persistence in the control plane filestore path

What you expected to happen:

Large or frequently updated stage logs should be persisted with lower peak allocation overhead and an encoding path that does not materialize avoidable intermediate payloads for every block.

How to reproduce it:

  1. Open pkg/app/server/stagelogstore/filestore.go.
  2. Inspect stageLogFileStore.Put around the existing performance TODO.
  3. Note that each call loops over all lf.Blocks, marshals each block individually, appends it to a bytes.Buffer, and finally calls filestore.Put with the complete byte slice.
  4. Add a focused benchmark that grows lf.Blocks and repeatedly calls Put.
  5. Observe allocation count and write cost grow with total block count because the full fragment is rebuilt for every save.

Environment:

  • piped version: repository checkout on 2026-07-13
  • control-plane version: repository checkout on 2026-07-13
  • Others: validated by current code inspection; previous related issue #40 was closed as stale, not fixed

Technical Evidence

  • pkg/app/server/stagelogstore/filestore.go:65-82 rebuilds the payload in memory for every Put
  • The code includes TODO: Reduce the number of marshaling log blocks for improving performance
  • Upstream issue #40 tracked the same performance concern but was auto-closed as stale without an implementation change

Suspected Root Cause

The filestore path is implemented as full-object persistence, and Put currently uses per-block json.Marshal calls plus a whole-fragment buffer build before every write.

Proposed Direction

Start with a benchmark for realistic stage-log sizes, then refactor the write path to stream JSON encoding into the final buffer or otherwise reduce avoidable intermediate allocations while preserving the existing line-delimited on-disk format and EOL completion marker.

Acceptance Criteria

  • A benchmark captures baseline throughput and allocations for larger stage-log fragments
  • The write path measurably reduces allocations or latency compared with the current implementation
  • Existing read compatibility for stored stage logs is preserved
  • No unrelated stage-log behavior changes are introduced
Ngôn ngữ chính
Go
Star
1.4k
Fork
391
Merge trung bình
4 ngày 1 giờ
Pull request đã merge (30 ngày)
58

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

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 pipe-cd/pipecd

Tất cả issue của pipe-cd/pipecd

Issue tương tự

Thêm issue về Go

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.