Repository navigation
Use lazy-regex for static regexes - #911
Conversation
Replace the `LazyLock::new(|| Regex::new(r"...").unwrap())` boilerplate with `lazy_regex!(r"...")` for all 84 static regexes in braille.rs, canonicalize.rs, interface.rs, tts.rs, infer_intent.rs, chemistry.rs, xpath_functions.rs and speech.rs. The macro checks each pattern at compile time, so an invalid regex fails the build instead of panicking on first use. No functional change: regexes are still compiled lazily by the regex crate. Regexes built at runtime (number separators, braille contractions) and non-regex LazyLocks are unchanged.
Linux library size: 0.59 MiB (+0.59%)
Built with default features, Rust 1.96.0, and Ubuntu 24.04. Workflow run. |
|
Claude says the failures on Windows are due to a race condition in prefs.rs, specifically copy_dir_all in line 1176, but I did not yet really look into the details here. |
|
I've been trying to come up with a fix for the update test. I did some work on it just before going into the hospital and it has just recently started showing up in the builds. It wasn't a problem before I made some improvements to something (I can't remember what). Can you ask Claude to figure out what change started causing the problem? I like this change. For some reason it adds +3,600 bytes (+0.59%). Any idea why? If anything, I would have thought it would be slightly smaller. Maybe the macro is too general in what it generates? |
|
I only added Windows to CI pretty recently, so most likely the flaky test didnt show up as it just wasn't run. I was also surprised to see the binary size increase. I can look into it. |
|
ok looks like the current way is broken anyway and throws away most of MathCAT:
|
|
How I see it, we need to properly do the binary size at some point, and we don't see it as a blocker here, as it is misleading. Then (apart from the Windows issue), this should be good to go. |
|
Ok. But it sounds like fixing the size measurement needs to be added as an issue. |
Replace the
LazyLock::new(|| Regex::new(r"...").unwrap())boilerplate withlazy_regex!(r"...")for all 84 static regexes in braille.rs, canonicalize.rs, interface.rs, tts.rs, infer_intent.rs, chemistry.rs, xpath_functions.rs and speech.rs. The macro checks each pattern at compile time, so an invalid regex fails the build instead of panicking on first use.No functional change: regexes are still compiled lazily by the regex crate. Regexes built at runtime (number separators, braille contractions) and non-regex LazyLocks are unchanged.
this removes quite a bit boilerplate, so I think this should be worth it (unless the memory footprint blows up from it, which I don't think will happen)