Skip to content

perf: avoid regex re-compile - #2700

Merged
Kludex merged 4 commits into
Kludex:masterfrom
trim21:perf-avoid-regex-compile
Sep 23, 2024
Merged

Kludex merged 4 commits into
Kludex:masterfrom
trim21:perf-avoid-regex-compile

Conversation

@trim21

@trim21 trim21 commented Sep 23, 2024

Copy link
Copy Markdown
Contributor

Summary

found re.findall and re.sub usage in starlette module, we should always pre-compile regex pattern if it's possible.

Althrough re has a built-in cache, but it has size limit and for project using many regex it still may be invalidated and pattern get unnecessary re-compile.

There is still one case in https://github.com/encode/starlette/blob/1131b3cbcd6f9e2aa3500fd4d7bf3cd200fa2532/starlette/_utils.py#L88

It's not a simple case so I didn't touch it.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

@trim21
trim21 marked this pull request as draft September 23, 2024 06:46
@trim21
trim21 marked this pull request as ready for review September 23, 2024 06:48
@Kludex

Kludex commented Sep 23, 2024

Copy link
Copy Markdown
Owner

Thanks! 馃檹

@Kludex
Kludex merged commit 9d4d5a5 into Kludex:master Sep 23, 2024
@trim21
trim21 deleted the perf-avoid-regex-compile branch September 23, 2024 06:55
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