Skip to content

Avoid allocation in isExtractFieldKeyword#99

Merged
joelmarcotte merged 1 commit into
mainfrom
joel.marcotte/SDBM-2597-perf
May 5, 2026
Merged

Avoid allocation in isExtractFieldKeyword#99
joelmarcotte merged 1 commit into
mainfrom
joel.marcotte/SDBM-2597-perf

Conversation

@joelmarcotte

Copy link
Copy Markdown
Contributor

Summary

  • Follow-up to Obfuscate EXTRACT field keywords #98. The original isExtractFieldKeyword used strings.ToUpper(value) to look up a map[string]struct{}, which allocates a folded copy of the input on every call.
  • Replace the map with a flat string slice and use strings.EqualFold for 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 an EXTRACT( 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

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>
@joelmarcotte joelmarcotte requested a review from a team as a code owner May 5, 2026 15:57
@joelmarcotte joelmarcotte changed the title [SDBM-2597] Avoid allocation in isExtractFieldKeyword Avoid allocation in isExtractFieldKeyword May 5, 2026
@joelmarcotte joelmarcotte merged commit 74f0d5b into main May 5, 2026
7 checks passed
@joelmarcotte joelmarcotte deleted the joel.marcotte/SDBM-2597-perf branch May 5, 2026 16:46
@joelmarcotte joelmarcotte mentioned this pull request May 5, 2026
2 tasks
joelmarcotte added a commit that referenced this pull request May 5, 2026
Adds entries for the three bug fixes (#89, #96, #98) and the perf
follow-up (#99) shipped since v0.2.1.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants