Skip to content

perf: fast-path in validateTraceID for clean trace IDs#28

Merged
ankurs merged 1 commit intomainfrom
perf/validate-trace-fast-path
Apr 4, 2026
Merged

perf: fast-path in validateTraceID for clean trace IDs#28
ankurs merged 1 commit intomainfrom
perf/validate-trace-fast-path

Conversation

@ankurs
Copy link
Copy Markdown
Member

@ankurs ankurs commented Apr 4, 2026

Summary

  • Adds a pre-scan loop in validateTraceID that checks if all bytes are already printable ASCII
  • If clean (the common case for UUIDs/hex trace IDs), returns the string directly without allocating a strings.Builder

Test plan

  • go test -race ./... passes
  • make lint — 0 issues

Summary by CodeRabbit

  • Chores
    • Optimized trace ID validation performance by adding a fast path for clean input, reducing unnecessary memory allocations in common cases.

Add a pre-scan loop that checks if all bytes are printable ASCII
before allocating a strings.Builder. Most trace IDs (UUIDs, hex)
are already clean, so this avoids one allocation per request.
Copilot AI review requested due to automatic review settings April 4, 2026 14:27
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9fa50920-a4e6-4cef-9a8c-dda9c68d8108

📥 Commits

Reviewing files that changed from the base of the PR and between 8099f41 and 09ce4ac.

📒 Files selected for processing (1)
  • notifier/notifier.go

📝 Walkthrough

Walkthrough

The validateTraceID function in notifier/notifier.go is optimized with a fast-path check that detects whether input bytes fall within printable ASCII range (0x20–0x7E). If all bytes are already clean, the truncated string returns immediately without string builder allocation; otherwise, the existing sanitization logic executes.

Changes

Cohort / File(s) Summary
TraceID Validation Optimization
notifier/notifier.go
Added fast-path check to validateTraceID that verifies all bytes are within printable ASCII range before proceeding to slower string building; returns early if input is already clean, avoiding unnecessary allocations.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through ASCII land,
Fast paths now in every hand,
No builders built when clean is shown,
Just skip ahead and call it home! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a fast-path optimization to validateTraceID for trace IDs that are already clean ASCII.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/validate-trace-fast-path

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes validateTraceID by adding a fast path that avoids allocating a strings.Builder when the trace ID is already composed of printable ASCII (the common case for UUID/hex trace IDs).

Changes:

  • Add a pre-scan to detect already-clean trace IDs and return early.
  • Keep existing sanitization logic as the slow path for “dirty” inputs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ankurs ankurs merged commit 9a99787 into main Apr 4, 2026
11 checks passed
@ankurs ankurs deleted the perf/validate-trace-fast-path branch April 4, 2026 14:50
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