Copilot commented on code in PR #1137:
URL: 
https://github.com/apache/skywalking-banyandb/pull/1137#discussion_r3278054810


##########
test/cases/measure/cmd/generate/capture.go:
##########
@@ -165,7 +165,8 @@ func runCapture(outputDir, serverAddr string) {
                }
 
                wantPath := filepath.Join(wantDirPath, testName+".yaml")
-               if writeErr := os.WriteFile(wantPath, respYAML, 0o600); 
writeErr != nil {
+               wantContent := append([]byte(licenseHeader), respYAML...)
+               if writeErr := os.WriteFile(wantPath, wantContent, 0o600); 
writeErr != nil {
                        fmt.Fprintf(os.Stderr, "  [ERROR] %s: write failed: 
%v\n", testName, writeErr)

Review Comment:
   `append([]byte(licenseHeader), respYAML...)` converts the same header string 
to a new byte slice on every iteration, adding avoidable allocations during 
capture. Consider precomputing the header as `[]byte` once (outside the loop) 
and then constructing `wantContent` with a single allocation (e.g., via 
`make`+`copy`) to keep capture runs more efficient.



##########
test/cases/measure/cmd/capture/capture_test.go:
##########
@@ -169,7 +185,8 @@ func TestCapture(t *testing.T) {
                }
 
                wantPath := filepath.Join(wantDirPath, testName+".yaml")
-               if writeErr := os.WriteFile(wantPath, respYAML, 0o600); 
writeErr != nil {
+               wantContent := append([]byte(casesMeasureData.LicenseHeader), 
respYAML...)
+               if writeErr := os.WriteFile(wantPath, wantContent, 0o600); 
writeErr != nil {
                        t.Errorf("  [ERROR] %s: write failed: %v", testName, 
writeErr)

Review Comment:
   `append([]byte(casesMeasureData.LicenseHeader), respYAML...)` creates a new 
`[]byte` copy of the header on every want-file write. Since this loop can write 
many fixtures, consider caching the header bytes once before the loop and 
composing each `wantContent` with a single allocation (e.g., `make`+`copy`) to 
reduce allocations and GC pressure.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to