Avoid allocation in isExtractFieldKeyword#99
Merged
Conversation
The previous map-based lookup called strings.ToUpper on every token, allocating a folded copy of the input. Switch to a flat slice walked with strings.EqualFold so the case-insensitive comparison is allocation-free. The set has 22 entries and the function only runs inside an EXTRACT(...) call, so the linear scan is trivial. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
lu-zhengda
approved these changes
May 5, 2026
2 tasks
joelmarcotte
added a commit
that referenced
this pull request
May 5, 2026
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
isExtractFieldKeywordusedstrings.ToUpper(value)to look up amap[string]struct{}, which allocates a folded copy of the input on every call.strings.EqualFoldfor the comparison — allocation-free, and 22 entries makes the linear scan trivial. The function only runs once per token after we've already confirmed we're inside anEXTRACT(call, so this isn't a hot path, but the wasted allocation was easy to remove.Test plan
go test ./...passes — all existing EXTRACT cases (positive, negative, mixed-case, unknown field) still produce the right output🤖 Generated with Claude Code