Reduce stage log Put allocation overhead in filestore persistence
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 1.4k
- Forks
- 364
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 84
Description
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:
- Open
pkg/app/server/stagelogstore/filestore.go. - Inspect
stageLogFileStore.Putaround the existing performance TODO. - Note that each call loops over all
lf.Blocks, marshals each block individually, appends it to abytes.Buffer, and finally callsfilestore.Putwith the complete byte slice. - Add a focused benchmark that grows
lf.Blocksand repeatedly callsPut. - Observe allocation count and write cost grow with total block count because the full fragment is rebuilt for every save.
Environment:
pipedversion: repository checkout on 2026-07-13control-planeversion: repository checkout on 2026-07-13- Others: validated by current code inspection; previous related issue
#40was closed as stale, not fixed
Technical Evidence
pkg/app/server/stagelogstore/filestore.go:65-82rebuilds the payload in memory for everyPut- The code includes
TODO: Reduce the number of marshaling log blocks for improving performance - Upstream issue
#40tracked 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pkg/app/server/stagelogstore/filestore.go, reading stageLogFileStore.Put around lines 65-82 and its performance TODO. Add the focused benchmark described in the issue for growing lf.Blocks, then compare allocations and write cost while checking existing read behavior. Done means measurable improvement, preserved line-delimited format and EOL marker, and no unrelated behavior changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100