Artifacts Associated With Ticket 2942697fffffffff
Ticket change [83bdbc9a76] (rid 117431) by tgl on 2010-01-30 06:46:24:
- assignee initialized to: "pvgoran"
- cmimetype initialized to: "text/plain"
- comment initialized to:
The attached test case "slowregexp.tcl" demonstrates a case that results in O(N^2) slowdown in execution of a regexp match, as a result of nested searches in crevdissect: the outer invocation searches for a suitable midpoint, and for each possible midpoint the inner execution checks all possible locations for its midpoint. I tested this against 8.5.7 but it doesn't look like the relevant files have changed since then. There are a number of ways that this might be attacked, but I attach a fairly simple patch that seems to improve matters for me. The idea is that to verify a midpoint requires a longest() call as well as recursively cdissect()ing the left and right sides --- but we could do the longest() check first since that's the fastest. This reduces the runtime of the given test case about 500X on my machine. There are two possible flaws in this solution: 1. It won't work if longest() depends on cdissect() having set up some state --- for instance, establishing backref string boundaries. As far as I can see, that isn't the case, but I'm no expert on this code so I might've missed something. I can say that the Tcl regression tests still pass, though. 2. It's conceivable that there are cases where this way is slower rather than faster. I can't answer that at all. The regression test cases seem to take just about the same amount of time as before, though. FYI, this problem was originally submitted to the Postgres project at http://archives.postgresql.org/pgsql-hackers/2010-01/msg02864.php
- foundin initialized to: "obsolete: 8.5.7"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "tgl"
- subsystem initialized to: "43. Regexp"
- title initialized to: "Pathologically slow regexp execution"
- type initialized to: "Bug"
Add attachment "slowregexp.tcl" [cd1a5f5b61] (rid 95824) by tgl on 2010-01-30 13:46:25.
Ticket change [3b558bcdad] (rid 112721) by tgl on 2010-01-30 13:46:25:
- icomment:
File Added - 360856: slowregexp.tcl
- login: "tgl"
- mimetype: "text/plain"
- username: "tgl"
- icomment:
Ticket change [900b8ae6a7] (rid 120375) by tgl on 2010-01-30 13:47:28:
- icomment:
File Added - 360857: regexp.patch
- login: "tgl"
- mimetype: "text/plain"
- username: "tgl"
- icomment:
Add attachment "regexp.patch" [3e5eb131ef] (rid 121252) by tgl on 2010-01-30 13:47:28.
Ticket change [7df2225037] (rid 97315) by dkf on 2010-02-01 07:40:47:
- icomment:
As far as I can see this works, and I can't see any problems with it. (The speedup is nearly 800 times on the sample case as it happens: 94.3s -> 120ms) Applied to HEAD. Backports still pending.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [556c76c354] (rid 94131) by dkf on 2010-02-01 07:47:05:
- assignee changed to: "dkf"
- priority changed to: "7 High"
- resolution changed to: "Accepted"
Ticket change [03c0c24046] (rid 119876) by dkf on 2010-02-01 18:12:25:
- icomment:
Backported to 8.5
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [57f8eba033] (rid 117720) by dkf on 2010-02-01 18:20:28:
- closedate changed to: "2010-02-01T11:20:28"
- closer changed to: "dkf"
- icomment:
allow_comments - 1 Backported to 8.4
- login: "dkf"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "dkf"