Skip to content

Optimize regexp matching

Jan Provaznik requested to merge jp-prompt-opt1 into master

What does this MR do and why?

Optimize regexp matching

Matching also "everything-before" is unnecessary and may be very slow on longer texts.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

pry(main)> str = File.read("./app/models/project.rb")
pry(main)> str.match(%r{(?<comment>--|#|//)[ \t]?[ \t]*(?<instruction>[^\r\n]{10,})\s*\Z}im)
# this is slow:
pry(main)> str.match(%r{(?<prefix>.*)(?<comment>--|#|//)[ \t]?[ \t]*(?<instruction>[^\r\n]{10,})\s*\Z}im)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Merge request reports