laskoviymishka commented on code in PR #2143:
URL: https://github.com/apache/iceberg-go/pull/2143#discussion_r4232138815


##########
puffin/puffin_reader_bench_test.go:
##########
@@ -0,0 +1,71 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package puffin_test
+
+import (
+       "bytes"
+       "fmt"
+       "testing"
+
+       "github.com/apache/iceberg-go/puffin"
+)
+
+var readAllBlobsBenchmarkSink []*puffin.BlobData
+
+func BenchmarkReadAllBlobs(b *testing.B) {
+       for _, blobCount := range []int{16, 256, 1024} {
+               b.Run(fmt.Sprintf("blobs=%d", blobCount), func(b *testing.B) {
+                       var buf bytes.Buffer
+                       writer, err := puffin.NewWriter(&buf)
+                       if err != nil {
+                               b.Fatal(err)
+                       }
+
+                       payload := make([]byte, 64)
+                       for i := range blobCount {

Review Comment:
   The writer emits blobs in ascending offset order, so the benchmark only hits 
the sort's already-sorted fast path and really measures the alloc savings, not 
the reorder cost the sort exists for. A shuffled-footer variant (or at least a 
note that this is the sorted-input case) would make the numbers exercise the 
path they're meant to characterize.



##########
puffin/puffin_reader.go:
##########
@@ -620,29 +620,25 @@ func (r *Reader) ReadAllBlobs() ([]*BlobData, error) {
                return nil, nil
        }
 
-       // Create index mapping to preserve original order
-       type indexedBlob struct {
-               index int
-               meta  BlobMetadata
+       // Sort indexes instead of copying BlobMetadata into a temporary slice.

Review Comment:
   Small wording thing: the comment says we sort indexes "instead of copying 
BlobMetadata", but each result still clones its metadata through 
`cloneBlobMetadata`. What actually went away is the temporary `indexedBlob` 
slice and the reflection-based `sort.Slice`, so I'd reword to point at that.



##########
puffin/puffin_reader_bench_test.go:
##########
@@ -0,0 +1,71 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package puffin_test
+
+import (
+       "bytes"
+       "fmt"
+       "testing"
+
+       "github.com/apache/iceberg-go/puffin"
+)
+
+var readAllBlobsBenchmarkSink []*puffin.BlobData
+
+func BenchmarkReadAllBlobs(b *testing.B) {
+       for _, blobCount := range []int{16, 256, 1024} {
+               b.Run(fmt.Sprintf("blobs=%d", blobCount), func(b *testing.B) {
+                       var buf bytes.Buffer
+                       writer, err := puffin.NewWriter(&buf)
+                       if err != nil {
+                               b.Fatal(err)
+                       }
+
+                       payload := make([]byte, 64)
+                       for i := range blobCount {
+                               _, err := 
writer.AddBlob(puffin.BlobMetadataInput{
+                                       Type:       
puffin.BlobTypeDataSketchesTheta,
+                                       SnapshotID: int64(i),
+                                       Fields:     []int32{1},
+                                       Properties: map[string]string{"ndv": 
"1"},
+                               }, payload)
+                               if err != nil {
+                                       b.Fatal(err)
+                               }
+                       }
+                       if err := writer.Finish(); err != nil {
+                               b.Fatal(err)
+                       }
+
+                       reader, err := 
puffin.NewReader(bytes.NewReader(buf.Bytes()))
+                       if err != nil {
+                               b.Fatal(err)
+                       }
+
+                       b.ReportAllocs()
+                       b.ResetTimer()

Review Comment:
   With `b.Loop()` the `ResetTimer` is redundant since Loop resets the timer on 
its first call, and the package-level `readAllBlobsBenchmarkSink` isn't needed 
either because Loop keeps the loop body's results alive. I'd drop both: keep 
`ReportAllocs` right before the loop and let `_ = blobs` stand in for the sink.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to