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

Add count to regex match, so only first occurance is matched #41

Merged
merged 1 commit into from Jun 13, 2022

Conversation

WillIrvine
Copy link
Contributor

@WillIrvine WillIrvine commented Jun 13, 2022

PR to limit the header pattern match in the XE driver to the first occurrence.

Justification:

The "S" flag in the pattern match is very slow in python regex.

OUTPUT_HEADER_PATTERN = re.compile( pattern=r".*(?=(version \d+\.\d+))", flags=re.I | re.S, )

Default behavior in Scrapli_Cfg is to run this regex pattern on the entire config file to remove any text before the actual configuration.

This pattern will only be seen once in a valid configuration file. This PR limits the match to the first occurrence, so that we don't have to regex the entire file, significantly speeding up the processing of the new config.

On my test config (>18000 lines), this speed up the processing from 2 hours, to less than a second, and still performed the required task of removing anything above the start of the configuration

From what i can see, the Async driver references this one, so we don't need to adjust anything there, and the other Cisco drivers don't use the "S" flag so won't have the same processing issue.

Let me know if there is anything i have missed or if you have any other contributing requirements.

Thanks

@WillIrvine WillIrvine changed the base branch from main to develop June 13, 2022 08:36
@carlmontanari
Copy link
Contributor

LGTM, thanks a bunch @WillIrvine !

@carlmontanari carlmontanari merged commit 957be0f into scrapli:develop Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants