Release unused file buffers for empty artifacts

This commit is contained in:
2026-10-09 01:52:06 +00:00
parent 389ef26db3
commit ea6c7d5f0f
5 changed files with 34 additions and 8 deletions

View File

@@ -42,7 +42,20 @@ func BenchmarkArtifactFileRead(b *testing.B) {
// BenchmarkRetainedArtifactFileRead measures live artifact bodies when an
// opened file reports a size larger than the content that reaches EOF.
func BenchmarkRetainedArtifactFileRead(b *testing.B) {
body := bytes.Repeat([]byte("x"), 256<<10)
for _, fixture := range []struct {
name string
body []byte
}{
{name: "small", body: bytes.Repeat([]byte("x"), 256<<10)},
{name: "empty", body: []byte{}},
} {
b.Run(fixture.name, func(b *testing.B) {
benchmarkRetainedArtifactFileRead(b, fixture.body)
})
}
}
func benchmarkRetainedArtifactFileRead(b *testing.B, body []byte) {
path := filepath.Join(b.TempDir(), "overreported.txt")
if err := os.WriteFile(path, body, 0o600); err != nil {
b.Fatal(err)