[Python-Dev] Make re.compile faster

Barry Warsaw barry at python.org
Tue Oct 3 10:21:55 EDT 2017


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.

-Barry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Message signed with OpenPGP
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171003/54cc9166/attachment.sig>


More information about the Python-Dev mailing list