pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix O(N^2) performance problems in regular-expression compiler. 6+ messages / 1 participants [nested] [flat]
* pgsql: Fix O(N^2) performance problems in regular-expression compiler. @ 2015-10-16 19:56 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2015-10-16 19:56 UTC (permalink / raw) To: pgsql-committers Fix O(N^2) performance problems in regular-expression compiler. Change the singly-linked in-arc and out-arc lists to be doubly-linked, so that arc deletion is constant time rather than having worst-case time proportional to the number of other arcs on the connected states. Modify the bulk arc transfer operations copyins(), copyouts(), moveins(), moveouts() so that they use a sort-and-merge algorithm whenever there's more than a small number of arcs to be copied or moved. The previous method is O(N^2) in the number of arcs involved, because it performs duplicate checking independently for each copied arc. The new method may change the ordering of existing arcs for the destination state, but nothing really cares about that. Provide another bulk arc copying method mergeins(), which is unused as of this commit but is needed for the next one. It basically is like copyins(), but the source arcs might not all come from the same state. Replace the O(N^2) bubble-sort algorithm used in carcsort() with a qsort() call. These changes greatly improve the performance of regex compilation for large or complex regexes, at the cost of extra space for arc storage during compilation. The original tradeoff was probably fine when it was made, but now we care more about speed and less about memory consumption. Back-patch to all supported branches. Branch ------ master Details ------- http://git.postgresql.org/pg/commitdiff/579840ca05e73ac23a3c2616f050333ba853fb34 Modified Files -------------- src/backend/regex/regc_nfa.c | 808 +++++++++++++++++++++++++++++++++++++----- src/backend/regex/regcomp.c | 10 +- src/include/regex/regguts.h | 4 +- 3 files changed, 728 insertions(+), 94 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix O(N^2) performance problems in regular-expression compiler. @ 2015-10-16 19:56 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2015-10-16 19:56 UTC (permalink / raw) To: pgsql-committers Fix O(N^2) performance problems in regular-expression compiler. Change the singly-linked in-arc and out-arc lists to be doubly-linked, so that arc deletion is constant time rather than having worst-case time proportional to the number of other arcs on the connected states. Modify the bulk arc transfer operations copyins(), copyouts(), moveins(), moveouts() so that they use a sort-and-merge algorithm whenever there's more than a small number of arcs to be copied or moved. The previous method is O(N^2) in the number of arcs involved, because it performs duplicate checking independently for each copied arc. The new method may change the ordering of existing arcs for the destination state, but nothing really cares about that. Provide another bulk arc copying method mergeins(), which is unused as of this commit but is needed for the next one. It basically is like copyins(), but the source arcs might not all come from the same state. Replace the O(N^2) bubble-sort algorithm used in carcsort() with a qsort() call. These changes greatly improve the performance of regex compilation for large or complex regexes, at the cost of extra space for arc storage during compilation. The original tradeoff was probably fine when it was made, but now we care more about speed and less about memory consumption. Back-patch to all supported branches. Branch ------ REL9_5_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/cff9e0659e8b79d4e075d30f04dac5a5587b8ac2 Modified Files -------------- src/backend/regex/regc_nfa.c | 808 +++++++++++++++++++++++++++++++++++++----- src/backend/regex/regcomp.c | 10 +- src/include/regex/regguts.h | 4 +- 3 files changed, 728 insertions(+), 94 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix O(N^2) performance problems in regular-expression compiler. @ 2015-10-16 19:56 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2015-10-16 19:56 UTC (permalink / raw) To: pgsql-committers Fix O(N^2) performance problems in regular-expression compiler. Change the singly-linked in-arc and out-arc lists to be doubly-linked, so that arc deletion is constant time rather than having worst-case time proportional to the number of other arcs on the connected states. Modify the bulk arc transfer operations copyins(), copyouts(), moveins(), moveouts() so that they use a sort-and-merge algorithm whenever there's more than a small number of arcs to be copied or moved. The previous method is O(N^2) in the number of arcs involved, because it performs duplicate checking independently for each copied arc. The new method may change the ordering of existing arcs for the destination state, but nothing really cares about that. Provide another bulk arc copying method mergeins(), which is unused as of this commit but is needed for the next one. It basically is like copyins(), but the source arcs might not all come from the same state. Replace the O(N^2) bubble-sort algorithm used in carcsort() with a qsort() call. These changes greatly improve the performance of regex compilation for large or complex regexes, at the cost of extra space for arc storage during compilation. The original tradeoff was probably fine when it was made, but now we care more about speed and less about memory consumption. Back-patch to all supported branches. Branch ------ REL9_4_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/bdde29e1ceb100d47cc212b6a39eeb5c8708a535 Modified Files -------------- src/backend/regex/regc_nfa.c | 808 +++++++++++++++++++++++++++++++++++++----- src/backend/regex/regcomp.c | 10 +- src/include/regex/regguts.h | 4 +- 3 files changed, 728 insertions(+), 94 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix O(N^2) performance problems in regular-expression compiler. @ 2015-10-16 19:56 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2015-10-16 19:56 UTC (permalink / raw) To: pgsql-committers Fix O(N^2) performance problems in regular-expression compiler. Change the singly-linked in-arc and out-arc lists to be doubly-linked, so that arc deletion is constant time rather than having worst-case time proportional to the number of other arcs on the connected states. Modify the bulk arc transfer operations copyins(), copyouts(), moveins(), moveouts() so that they use a sort-and-merge algorithm whenever there's more than a small number of arcs to be copied or moved. The previous method is O(N^2) in the number of arcs involved, because it performs duplicate checking independently for each copied arc. The new method may change the ordering of existing arcs for the destination state, but nothing really cares about that. Provide another bulk arc copying method mergeins(), which is unused as of this commit but is needed for the next one. It basically is like copyins(), but the source arcs might not all come from the same state. Replace the O(N^2) bubble-sort algorithm used in carcsort() with a qsort() call. These changes greatly improve the performance of regex compilation for large or complex regexes, at the cost of extra space for arc storage during compilation. The original tradeoff was probably fine when it was made, but now we care more about speed and less about memory consumption. Back-patch to all supported branches. Branch ------ REL9_3_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/296241635bc678f6766040e0c983e95d19b7ddf4 Modified Files -------------- src/backend/regex/regc_nfa.c | 808 +++++++++++++++++++++++++++++++++++++----- src/backend/regex/regcomp.c | 10 +- src/include/regex/regguts.h | 4 +- 3 files changed, 728 insertions(+), 94 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix O(N^2) performance problems in regular-expression compiler. @ 2015-10-16 19:56 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2015-10-16 19:56 UTC (permalink / raw) To: pgsql-committers Fix O(N^2) performance problems in regular-expression compiler. Change the singly-linked in-arc and out-arc lists to be doubly-linked, so that arc deletion is constant time rather than having worst-case time proportional to the number of other arcs on the connected states. Modify the bulk arc transfer operations copyins(), copyouts(), moveins(), moveouts() so that they use a sort-and-merge algorithm whenever there's more than a small number of arcs to be copied or moved. The previous method is O(N^2) in the number of arcs involved, because it performs duplicate checking independently for each copied arc. The new method may change the ordering of existing arcs for the destination state, but nothing really cares about that. Provide another bulk arc copying method mergeins(), which is unused as of this commit but is needed for the next one. It basically is like copyins(), but the source arcs might not all come from the same state. Replace the O(N^2) bubble-sort algorithm used in carcsort() with a qsort() call. These changes greatly improve the performance of regex compilation for large or complex regexes, at the cost of extra space for arc storage during compilation. The original tradeoff was probably fine when it was made, but now we care more about speed and less about memory consumption. Back-patch to all supported branches. Branch ------ REL9_2_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/a2ad467ae4a09c79488044c552edfa40724f41c6 Modified Files -------------- src/backend/regex/regc_nfa.c | 808 +++++++++++++++++++++++++++++++++++++----- src/backend/regex/regcomp.c | 10 +- src/include/regex/regguts.h | 4 +- 3 files changed, 728 insertions(+), 94 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix O(N^2) performance problems in regular-expression compiler. @ 2015-10-16 19:56 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2015-10-16 19:56 UTC (permalink / raw) To: pgsql-committers Fix O(N^2) performance problems in regular-expression compiler. Change the singly-linked in-arc and out-arc lists to be doubly-linked, so that arc deletion is constant time rather than having worst-case time proportional to the number of other arcs on the connected states. Modify the bulk arc transfer operations copyins(), copyouts(), moveins(), moveouts() so that they use a sort-and-merge algorithm whenever there's more than a small number of arcs to be copied or moved. The previous method is O(N^2) in the number of arcs involved, because it performs duplicate checking independently for each copied arc. The new method may change the ordering of existing arcs for the destination state, but nothing really cares about that. Provide another bulk arc copying method mergeins(), which is unused as of this commit but is needed for the next one. It basically is like copyins(), but the source arcs might not all come from the same state. Replace the O(N^2) bubble-sort algorithm used in carcsort() with a qsort() call. These changes greatly improve the performance of regex compilation for large or complex regexes, at the cost of extra space for arc storage during compilation. The original tradeoff was probably fine when it was made, but now we care more about speed and less about memory consumption. Back-patch to all supported branches. Branch ------ REL9_1_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/b00c79b5b97422e425e1feb16327d3eba5fcd228 Modified Files -------------- src/backend/regex/regc_nfa.c | 808 +++++++++++++++++++++++++++++++++++++----- src/backend/regex/regcomp.c | 10 +- src/include/regex/regguts.h | 4 +- 3 files changed, 728 insertions(+), 94 deletions(-) -- Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-committers ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2015-10-16 19:56 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2015-10-16 19:56 pgsql: Fix O(N^2) performance problems in regular-expression compiler. Tom Lane <tgl@sss.pgh.pa.us> 2015-10-16 19:56 pgsql: Fix O(N^2) performance problems in regular-expression compiler. Tom Lane <tgl@sss.pgh.pa.us> 2015-10-16 19:56 pgsql: Fix O(N^2) performance problems in regular-expression compiler. Tom Lane <tgl@sss.pgh.pa.us> 2015-10-16 19:56 pgsql: Fix O(N^2) performance problems in regular-expression compiler. Tom Lane <tgl@sss.pgh.pa.us> 2015-10-16 19:56 pgsql: Fix O(N^2) performance problems in regular-expression compiler. Tom Lane <tgl@sss.pgh.pa.us> 2015-10-16 19:56 pgsql: Fix O(N^2) performance problems in regular-expression compiler. Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions for how to clone and mirror all data and code used for this inbox