Skip to content

perf: Add fast-path checks to time function rewrites#99

Merged
xe-nvdk merged 1 commit intomainfrom
fix/time-function-rewrite-fast-path
Jan 7, 2026
Merged

perf: Add fast-path checks to time function rewrites#99
xe-nvdk merged 1 commit intomainfrom
fix/time-function-rewrite-fast-path

Conversation

@xe-nvdk
Copy link
Member

@xe-nvdk xe-nvdk commented Jan 7, 2026

Add early-exit checks to rewriteTimeBucket() and rewriteDateTrunc() to skip expensive regex operations when the SQL doesn't contain the target function names.

Before this change, ReplaceAllStringFunc was called on every query even when no patterns matched, causing unnecessary allocations:

  • time_bucket patterns: 16 allocs, 41KB per query
  • date_trunc pattern: 5 allocs, 2.3KB per query

With fast-path checks using strings.Contains:

  • Queries without time functions: ~15-19% faster
  • Eliminates ~44KB of allocations per query
  • Zero impact on queries that DO use time functions

Benchmark results (ns/op):

  • simple_select: 15,824 → 13,424 (-15%)
  • complex_query: 46,971 → 38,142 (-19%)

Add early-exit checks to rewriteTimeBucket() and rewriteDateTrunc()
to skip expensive regex operations when the SQL doesn't contain
the target function names.

Before this change, ReplaceAllStringFunc was called on every query
even when no patterns matched, causing unnecessary allocations:
- time_bucket patterns: 16 allocs, 41KB per query
- date_trunc pattern: 5 allocs, 2.3KB per query

With fast-path checks using strings.Contains:
- Queries without time functions: ~15-19% faster
- Eliminates ~44KB of allocations per query
- Zero impact on queries that DO use time functions

Benchmark results (ns/op):
- simple_select: 15,824 → 13,424 (-15%)
- complex_query: 46,971 → 38,142 (-19%)
@xe-nvdk xe-nvdk merged commit cc012c1 into main Jan 7, 2026
3 checks passed
xe-nvdk added a commit that referenced this pull request Jan 7, 2026
- Fix compile error: configureDatabase now receives logger parameter
- Fix unused parameter warning in buildDSN
- Update release notes for PR #92 (Azure SSL fix) and PR #99 (fast-path optimization)
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.

1 participant