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

Inefficient regex in extract_full_summary_from_signature #281

Open
jiasli opened this issue Mar 19, 2024 · 0 comments
Open

Inefficient regex in extract_full_summary_from_signature #281

jiasli opened this issue Mar 19, 2024 · 0 comments

Comments

@jiasli
Copy link
Member

jiasli commented Mar 19, 2024

As pointed out by https://gist.github.com/prodigysml/d07cd482214c80bfb6d3240454d2f679, this regex (introduced by 430c39e) is inefficient:

regex = r'\s*(:param)\s+(.+?)\s*:(.*)'

As shown in https://regex101.com/, a simple :param r requires 1214 steps to fail.

image

This is because \s+, .+? and \s* all match consecutive spaces, thus can trigger many backtrackings.

A better solution is to replace .+? with \w+ to match the parameter name so that backtrackings can be greatly reduced:

\s*(:param)\s+(\w+)\s*:(.*)

image

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

No branches or pull requests

1 participant