Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
regexp: Optimize for inputs that are provably too short #31329
I'm following up on my work on
For many patterns we can compute the minimum length of the input at compile time. For instance, an HTTP router might use a pattern like
If the input is shorter than that, as may happen quite frequently, we can return early and get a huge speedup.
Some benchmarks are included in the CL.
It's interesting to note that Perl's regex engine contains a number of these kinds of fail-fast optimizations: https://perldoc.perl.org/perlreguts.html#Peep-hole-Optimisation-and-Analysis