Dynamo icon indicating copy to clipboard operation
Dynamo copied to clipboard

Static regexes

Open bendikberg opened this issue 9 months ago • 0 comments

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

bendikberg avatar Feb 25 '25 12:02 bendikberg