You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by ze...@apache.org on 2026/08/14 16:01:29 UTC
(iceberg-go) branch main updated: perf(expr): pre-size literal sets (#1812)
This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-go.git
The following commit(s) were added to refs/heads/main by this push:
new 3a21b192b perf(expr): pre-size literal sets (#1812)
3a21b192b is described below
commit 3a21b192b5facc6cfbb99b5603ecc4eec802bdd9
Author: Minh Vu <vu...@gmail.com>
AuthorDate: Fri Aug 14 18:01:23 2026 +0200
perf(expr): pre-size literal sets (#1812)
---
exprs.go | 2 +-
exprs_literal_set_bench_test.go | 67 +++++++++++++++++++++++++++++++++++++++++
utils.go | 2 +-
3 files changed, 69 insertions(+), 2 deletions(-)
diff --git a/exprs.go b/exprs.go
index 172916752..bc3ddccef 100644
--- a/exprs.go
+++ b/exprs.go
@@ -950,7 +950,7 @@ type BoundSetPredicate interface {
func createBoundSetPredicate(op Operation, term BoundTerm, lits Set[Literal]) (BooleanExpression, error) {
boundType := term.Type()
- typedSet := newLiteralSet()
+ typedSet := make(literalSet, lits.Len())
for _, v := range lits.Members() {
casted, err := v.To(boundType)
if err != nil {
diff --git a/exprs_literal_set_bench_test.go b/exprs_literal_set_bench_test.go
new file mode 100644
index 000000000..9df127dea
--- /dev/null
+++ b/exprs_literal_set_bench_test.go
@@ -0,0 +1,67 @@
+// 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 iceberg
+
+import (
+ "strconv"
+ "testing"
+)
+
+var (
+ benchmarkLiteralSetSink Set[Literal]
+ benchmarkBooleanExprSink BooleanExpression
+)
+
+func benchmarkLiteralSetValues(size int) []Literal {
+ values := make([]Literal, size)
+ for i := range values {
+ values[i] = NewLiteral(int32(i))
+ }
+
+ return values
+}
+
+func BenchmarkNewLiteralSet(b *testing.B) {
+ for _, size := range []int{8, 64, 1024, 8192} {
+ values := benchmarkLiteralSetValues(size)
+ b.Run(strconv.Itoa(size), func(b *testing.B) {
+ b.ReportAllocs()
+ for range b.N {
+ benchmarkLiteralSetSink = newLiteralSet(values...)
+ }
+ })
+ }
+}
+
+func BenchmarkBindLiteralSet(b *testing.B) {
+ schema := NewSchema(1, NestedField{ID: 1, Name: "value", Type: PrimitiveTypes.Int32})
+ for _, size := range []int{8, 64, 1024, 8192} {
+ values := benchmarkLiteralSetValues(size)
+ predicate := SetPredicate(OpIn, Reference("value"), values).(UnboundPredicate)
+ b.Run(strconv.Itoa(size), func(b *testing.B) {
+ b.ReportAllocs()
+ for range b.N {
+ var err error
+ benchmarkBooleanExprSink, err = predicate.Bind(schema, true)
+ if err != nil {
+ b.Fatal(err)
+ }
+ }
+ })
+ }
+}
diff --git a/utils.go b/utils.go
index daaaa6566..1af5631ee 100644
--- a/utils.go
+++ b/utils.go
@@ -120,7 +120,7 @@ var lzseed = maphash.MakeSeed()
type literalSet map[any]struct{ orig Literal }
func newLiteralSet(vals ...Literal) Set[Literal] {
- s := literalSet{}
+ s := make(literalSet, len(vals))
for _, v := range vals {
s.addliteral(v)
}