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/arrow-go.git
The following commit(s) were added to refs/heads/main by this push:
new d3f3b981 optimization: compare: avoid initializing config when it's
not needed (#563)
d3f3b981 is described below
commit d3f3b981acc9e7174f15a28b2bc47137c5b64688
Author: pixelherodev <[email protected]>
AuthorDate: Fri Nov 7 17:01:15 2025 -0600
optimization: compare: avoid initializing config when it's not needed (#563)
This makes Schema.Equal ~20% faster in my use case (where the hot path
is almost always taken, left == right).
cfg escapes to the heap; this change avoids making cfg exist until after
the hot path, making it even faster.
### Rationale for this change
### What changes are included in this PR?
### Are these changes tested?
### Are there any user-facing changes?
Co-authored-by: Noam Preil <[email protected]>
---
arrow/compare.go | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/arrow/compare.go b/arrow/compare.go
index 644de8e1..e2c8ada1 100644
--- a/arrow/compare.go
+++ b/arrow/compare.go
@@ -40,11 +40,6 @@ func CheckMetadata() TypeEqualOption {
// TypeEqual checks if two DataType are the same, optionally checking metadata
// equality for STRUCT types.
func TypeEqual(left, right DataType, opts ...TypeEqualOption) bool {
- var cfg typeEqualsConfig
- for _, opt := range opts {
- opt(&cfg)
- }
-
switch {
case left == right:
return true
@@ -54,6 +49,11 @@ func TypeEqual(left, right DataType, opts
...TypeEqualOption) bool {
return false
}
+ var cfg typeEqualsConfig
+ for _, opt := range opts {
+ opt(&cfg)
+ }
+
switch l := left.(type) {
case ExtensionType:
return l.ExtensionEquals(right.(ExtensionType))