chore: lazy-compile validation regexes via std::sync::LazyLock - #830
Merged
Conversation
The 4 constant-source regexes in core/validations/message.rs (FNAME, TWITTER_USERNAME, GITHUB_USERNAME, geo) were being recompiled with fancy_regex::Regex::new(...) on every call to validate_fname, validate_ens_name, validate_base_name, validate_twitter_username, validate_github_username, and validate_user_location. Move them to module-level static LazyLock<Regex> so each compiles exactly once. The CAIP-19 regex is dynamically constructed from a local variable and is left as-is. Aligns with the intent of #576; uses stable std::sync::LazyLock (stabilized in Rust 1.80) instead of lazy_static!. Split out from #796 per review feedback. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves performance in hot-path message validation by compiling several constant regex patterns once at module initialization time (lazy, on first use) instead of recompiling them on every validation call.
Changes:
- Introduces module-level
static LazyLock<Regex>instances for fname, Twitter username, GitHub username, and geo location regexes. - Updates the corresponding validation functions to reuse the cached compiled regexes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5 tasks
Diff CoverageDiff: origin/main...HEAD, staged and unstaged changes
Summary
src/core/validations/message.rs |
topocount
approved these changes
Apr 27, 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
The 4 constant-source regexes in
core/validations/message.rs(FNAME_REGEX,TWITTER_USERNAME_REGEX,GITHUB_USERNAME_REGEX, geo) were being recompiled withfancy_regex::Regex::new(...)on every call tovalidate_fname,validate_ens_name,validate_base_name,validate_twitter_username,validate_github_username, andvalidate_user_location. Each is hot-path validation code.Moves them to module-level
static LazyLock<Regex>so each compiles exactly once. The CAIP-19 regex is dynamically constructed from a local variable (depends on namespace input), so it's left as-is.Aligns with the intent of #576; uses stable
std::sync::LazyLock(stabilized in Rust 1.80) instead oflazy_static!oronce_cell. Split out from #796 per review feedback.Test plan
🤖 Generated with Claude Code