Skip to content

Conversation

@shakfu
Copy link
Contributor

@shakfu shakfu commented Jan 29, 2026

I've added some pure-python optimizations which improve performance by 30% or so.

  1. Pre-compile regex patterns at module level instead of compiling on every function call
  2. Use list accumulation with "".join() instead of O(n²) string concatenation
  3. Cache dynamically-generated regex patterns to avoid repeated compilation

These are standard Python optimization techniques that require no additional dependencies.

I've also added the docs/optimizations.md document to explain these in more detail.

@jhidding
Copy link
Contributor

Oh, this is so cool! Thank you, also for the extensive documentation and explanations. :)

About the caching of regexes: I read in the documention that Python is already performing this sort of caching on its own, but I never tested this.

@jhidding jhidding merged commit 2e61fcf into entangled:main Jan 29, 2026
6 checks passed
@shakfu
Copy link
Contributor Author

shakfu commented Jan 29, 2026

Oh, this is so cool! Thank you, also for the extensive documentation and explanations. :)

My pleasure.

About the caching of regexes: I read in the documention that Python is already performing this sort of caching on its own, but I never tested this.

I didn't know they were cached either!

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