Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static regexes #15858

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bendikberg
Copy link
Contributor

Purpose

Dynamo uses a lot of regexes in many places, many of which can be made static, since the regex pattern never changes. This PR changes most of the regexes I could find where the pattern never changes to a static compiled regex.

Adding the Compiled option to the Regex creation flags increases construction time a little, but creates a faster regex.

There is a fairly recent C# feature for compiling regex into the .dll using attributes. I did not want to move regexes around or change classes to be partial, so I avoided this. Using that feature would probably lead to bigger performance gains.

Performance

Example gain:

Code block instantiation (old)
regex_instantiate

Code block instantiation (new)
regex_cached

Every function that uses regex and gets called multiple times in quick succession (probably) gains a fair amount of speed from this, as the regex construction and compilation is avoided. See for example the unit or PII methods, which I would imagine are called fairly often in actual Dynamo use, and which use large and complicated regex expressions.

Declarations

Check these if you believe they are true

  • The codebase is in a better state after this PR
  • Is documented according to the standards
  • The level of testing this PR includes is appropriate
  • User facing strings, if any, are extracted into *.resx files
  • All tests pass using the self-service CI.
  • Snapshot of UI changes, if any.
  • Changes to the API follow Semantic Versioning and are documented in the API Changes document.
  • This PR modifies some build requirements and the readme is updated
  • This PR contains no files larger than 50 MB

Release Notes

N/A

Reviewers

@mjkkirschner

FYIs

@dimven

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants