Re: [Python-Dev] Make re.compile faster

2017-10-03 Thread Serhiy Storchaka
03.10.17 17:21, Barry Warsaw пише: 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

Re: [Python-Dev] Make re.compile faster

2017-10-03 Thread Stefan Behnel
INADA Naoki schrieb am 03.10.2017 um 05:29: > Before deferring re.compile, can we make it faster? I tried cythonizing both sre_compile.py and sre_parse.py, which gave me a speedup of a bit more than 2x. There is definitely space left for further improvements since I didn't know much about the code

Re: [Python-Dev] Make re.compile faster

2017-10-03 Thread Antoine Pitrou
On Tue, 3 Oct 2017 10:21:55 -0400 Barry Warsaw wrote: > On Oct 3, 2017, at 01:41, Serhiy Storchaka 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. > > > >

Re: [Python-Dev] Make re.compile faster

2017-10-03 Thread Barry Warsaw
On Oct 3, 2017, at 01:41, Serhiy Storchaka 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.

Re: [Python-Dev] Make re.compile faster

2017-10-03 Thread Barry Warsaw
On Oct 3, 2017, at 01:35, Serhiy Storchaka wrote: > >> diff --git a/Lib/string.py b/Lib/string.py >> index b46e60c38f..fedd92246d 100644 >> --- a/Lib/string.py >> +++ b/Lib/string.py >> @@ -81,7 +81,7 @@ class Template(metaclass=_TemplateMetaclass): >> delimiter = '$' >> idpattern = r'[

Re: [Python-Dev] Make re.compile faster

2017-10-03 Thread Victor Stinner
> * RegexFlag.__and__ and __new__ is called very often. Yeah, when the re module was modified to use enums for flags, re.compile() became slower: https://pyperformance.readthedocs.io/cpython_results_2017.html#slowdown https://speed.python.org/timeline/#/?exe=12&ben=regex_compile&env=1&revs=200&eq

Re: [Python-Dev] Make re.compile faster

2017-10-02 Thread Serhiy Storchaka
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 correctnes

Re: [Python-Dev] Make re.compile faster

2017-10-02 Thread Serhiy Storchaka
03.10.17 06:29, INADA Naoki пише: Before deferring re.compile, can we make it faster? I profiled `import string` and small optimization can make it 2x faster! (but it's not backward compatible) Please open an issue for this. I found: * RegexFlag.__and__ and __new__ is called very often. * _

[Python-Dev] Make re.compile faster

2017-10-02 Thread INADA Naoki
Before deferring re.compile, can we make it faster? I profiled `import string` and small optimization can make it 2x faster! (but it's not backward compatible) Before optimize: import time: self [us] | cumulative | imported package import time: 2339 | 9623 | string string module took