[Python-Dev] Make re.compile faster
Antoine Pitrou
solipsis at pitrou.net
Tue Oct 3 10:30:17 EDT 2017
On Tue, 3 Oct 2017 10:21:55 -0400
Barry Warsaw <barry at python.org> wrote:
> On Oct 3, 2017, at 01:41, Serhiy Storchaka <storchaka at gmail.com> wrote:
> >
> > 03.10.17 06:29, INADA Naoki пише:
> >> More optimization can be done with implementing sre_parse and sre_compile in C.
> >> But I have no time for it in this year.
> >
> > And please don't do this! This would make maintaining the re module hard. The performance of the compiler is less important than correctness and performance of matching and searching.
>
> What if the compiler could recognize constant arguments to re.compile() and do the regex compilation at that point? You’d need a way to represent the precompiled regex in the bytecode, and it would technically be a semantic change since regex problems would be discovered at compilation time instead of runtime - but that might be a good thing. You could also make that an optimization flag for opt-in, or a flag to allow opt out.
We need a regex literal!
With bytes, formatted, and bytes formatted variants.
Regards
Antoine.
More information about the Python-Dev
mailing list