Ma Lin <malin...@163.com> added the comment: PR11926 (closed) tried to allocate SRE_REPEAT on state's stack. It's feasible, but messes up the code in sre_lib.h, and reduces performance a little (roughly 6% slower), so I gave up this solution.
PR12160 uses a memory pool, this solution doesn't mess up the code. 🔸For infrequent alloc/free scenes, it adds a small overhead: s = 'a' p = re.compile(r'(a)?') p.match(s) # <- measure this statement before patch: 316 ns +- 19 ns after patch: 324 ns +- 11 ns, 2.5% slower. (by perf module) 🔸For very frequent alloc/free scenes, it brings a speedup: s = 200_000_000 * 'a' p = re.compile(r'.*?(?:bb)+') p.match(s) # <- measure this statement before patch: 7.16 sec after patch: 5.82 sec, 18.7% faster. (best of 10 tests) 🔸I tested in a real case that use 17 patterns to process 100MB data: before patch: 27.09 sec after patch: 26.78 sec, 1.1% faster. (best of 4 tests) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue23689> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com