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

Use named list for regex substitution of namespace prefixes #708

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

apasel422
Copy link
Contributor

@apasel422 apasel422 commented Jun 17, 2024

I profiled se lint because it seemed to be surprisingly slow on a fairly small ebook repository. This revealed that half of the execution time was spent in the _replace_shorthand_namespaces method.

For the same repository, changing that method to use a named list (and therefore, only a single call to regex.sub) reduced the time spent in that method from ~15 seconds to ~5 seconds. This optimization is correct, and arguably easier to understand, because a single attribute can only have one prefix.

Using a named list also avoids the need to manually escape the prefixes before including them in the regex pattern, which this code was incorrectly skipping.

Finally, this change corrects a mistake in that method's documentation, as the : suffix is not retained in the output.

I profiled se lint because it seemed to be surprisingly slow for a
fairly small repository. This revealed that half of the execution time
was spent in the _replace_shorthand_namespaces method.

For the same repository, changing that method to use a named list (and
therefore, only a single call to regex.sub) reduced the time spent in
that method from ~15 seconds to ~5 seconds. This optimization is
correct, and arguably easier to understand, because a single attribute
can only have one prefix.

Using a named list also avoids the need to manually escape the prefixes
before including them in the regex pattern, which this code was
incorrectly skipping.

Finally, this change corrects a mistake in that method's documentation,
as the : suffix is not retained in the output.
@apasel422 apasel422 marked this pull request as ready for review June 17, 2024 16:45
@acabal acabal merged commit 6ee7e3a into standardebooks:master Jun 17, 2024
1 check passed
@acabal
Copy link
Member

acabal commented Jun 17, 2024

Great optimization, thanks!

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