fix: eliminate per-element heap allocs in is_in kernel for binary types#745
Open
zeroshade wants to merge 1 commit intoapache:mainfrom
Open
fix: eliminate per-element heap allocs in is_in kernel for binary types#745zeroshade wants to merge 1 commit intoapache:mainfrom
zeroshade wants to merge 1 commit intoapache:mainfrom
Conversation
Add BinaryMemoTable.ExistsDirect that inlines the hash table probe loop, avoiding the closure in HashTable.Lookup that causes val to escape. Add isInBinaryDirect that bypasses the visitBinary and VisitBitBlocksShort closure chain by directly iterating with OptionalBitBlockCounter. Closes apache#736 Benchmark (100k rows, 10-element value set): Before: 4,133,679 ns/op 2,435,327 B/op 100,075 allocs/op After: 923,565 ns/op 33,092 B/op 70 allocs/op
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BinaryMemoTable.ExistsDirectthat inlines the hash table probe loop, avoiding the closure inHashTable.Lookupthat causesval []byteto escape to the heapisInBinaryDirectspecialized kernel path that bypasses thevisitBinary→VisitBitBlocksShortclosure chain by directly iterating withOptionalBitBlockCounterBinaryDataTypedispatch inDispatchIsInto the new direct path (handles both int32 and int64 offsets)Motivation
The
is_inkernel for binary types allocated once per input element because the[]bytevalue escaped to the heap through a closure chain:visitBinaryslicesrawBytes[offsets[pos]:offsets[pos+1]]and passes to a callbackBinaryMemoTable.Exists(v)Existscallslookupwhich creates a closure capturingvalHashTable.Lookup, causing escape analysis to movevalto the heapCloses #736
Benchmark (100k rows, 10-element value set)
All existing
TestIsInBinarysubtests pass (binary, large_binary, utf8, large_utf8 × all null matching behaviors).