From 91692846909ed191addb7ec1c34aad11392ab88b Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 18 Jul 2026 15:03:55 +0900 Subject: perf(regex): eliminate per-call clone overhead in preg_* dispatch regex::Regex::clone() does not share the underlying meta engine's search-cache pool, so every fresh clone pays a ~10us warmup cost on its first use. Two changes together eliminate this across nearly all preg_* call sites: - A php_regex! macro resolves PHP-style patterns to a per-call-site &'static regex::Regex (via regex-macro's LazyLock), applied at the majority of call sites throughout the codebase. - Call sites still passing dynamic pattern strings go through PATTERN_CACHE, which now stores Arc<(Regex, bool)> and hands out Arc::clone()s instead of cloning the Regex itself. PregPattern::resolve() returns a ResolvedPattern enum (Arc or 'static reference) rather than an owned Regex, so neither path ever clones the Regex proper. Co-Authored-By: Claude Sonnet 5 --- crates/shirabe/src/downloader/svn_downloader.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'crates/shirabe/src/downloader/svn_downloader.rs') diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs index cd48daeb..b2dd7f58 100644 --- a/crates/shirabe/src/downloader/svn_downloader.rs +++ b/crates/shirabe/src/downloader/svn_downloader.rs @@ -16,7 +16,7 @@ use crate::util::ProcessExecutor; use crate::util::Svn as SvnUtil; use indexmap::IndexMap; use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; -use shirabe_php_shim::{PhpMixed, RuntimeException, is_dir, version_compare}; +use shirabe_php_shim::{PhpMixed, RuntimeException, is_dir, php_regex, version_compare}; #[derive(Debug)] pub struct SvnDownloader { @@ -278,7 +278,7 @@ impl VcsDownloader for SvnDownloader { } let changes_str = changes.unwrap(); - let changes: Vec = Preg::split(r"{\s*\r?\n\s*}", &changes_str) + let changes: Vec = Preg::split(php_regex!(r"{\s*\r?\n\s*}"), &changes_str) .into_iter() .map(|elem| format!(" {}", elem)) .collect(); @@ -364,8 +364,8 @@ impl VcsDownloader for SvnDownloader { to_reference: &str, path: &str, ) -> anyhow::Result { - if Preg::is_match(r"{@(\d+)$}", from_reference) - && Preg::is_match(r"{@(\d+)$}", to_reference) + if Preg::is_match(php_regex!(r"{@(\d+)$}"), from_reference) + && Preg::is_match(php_regex!(r"{@(\d+)$}"), to_reference) { // retrieve the svn base url from the checkout folder let command = vec![ @@ -411,8 +411,8 @@ impl VcsDownloader for SvnDownloader { }; // strip paths from references and only keep the actual revision - let from_revision = Preg::replace(r"{.*@(\d+)$}", "$1", from_reference); - let to_revision = Preg::replace(r"{.*@(\d+)$}", "$1", to_reference); + let from_revision = Preg::replace(php_regex!(r"{.*@(\d+)$}"), "$1", from_reference); + let to_revision = Preg::replace(php_regex!(r"{.*@(\d+)$}"), "$1", to_reference); let command = vec![ "svn".to_string(), @@ -469,7 +469,7 @@ impl ChangeReportInterface for SvnDownloader { Some(path), ); - Ok(if Preg::is_match("{^ *[^X ] +}m", &output) { + Ok(if Preg::is_match(php_regex!("{^ *[^X ] +}m"), &output) { Some(output) } else { None -- cgit v1.3.1