Skip to content

Replace Regex with lazy-regex - #7

Open
ZedThree wants to merge 1 commit into
sbryngelson:masterfrom
PlasmaFAIR:lazy-regex
Open

Replace Regex with lazy-regex#7
ZedThree wants to merge 1 commit into
sbryngelson:masterfrom
PlasmaFAIR:lazy-regex

Conversation

@ZedThree

Copy link
Copy Markdown

The uses of Regex in formatter.rs were not being constructed lazily or with OnceLock, meaning that the cost of constructing them was being paid every single time the containing function was called.

Constructing them lazily gives a significant performance enhancement (~15x in some cases).

Using the lazy-regex crate simplifies the construction of lazy+static regexes, and has some other benefits (compile time checking, for instance).

Improvement is most noticeable on large files (>1k lines), where running ffmt --check can go from ~800ms to ~50ms.

The uses of `Regex` in `formatter.rs` were not being constructed lazily or with
`OnceLock`, meaning that the cost of constructing them was being paid every
single time the containing function was called.

Constructing them lazily gives a significant performance enhancement (~15x in
some cases).

Using the [`lazy-regex`](https://docs.rs/lazy-regex/latest/lazy_regex/) crate
simplifies the construction of lazy+static regexes, and has some other benefits
(compile time checking, for instance).
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