]> granicus.if.org Git - re2c/commitdiff
libre2c: found pathological case for constant-memory POSIX algorithms.
authorUlya Trofimovich <skvadrik@gmail.com>
Wed, 20 Feb 2019 17:00:47 +0000 (17:00 +0000)
committerUlya Trofimovich <skvadrik@gmail.com>
Wed, 20 Feb 2019 17:00:47 +0000 (17:00 +0000)
The regexp is ((a?){1,200})*, and the input string is just "a".

Takes quibic time in the size of counter. This is caused by quadratic-
time computation of precedence matrix on each step (the number of TNFA
states in the closure approaches TNFA size), multiplied by the length
of compared histores (which also approaches TNFA size). Trie-based
algorithms are not affected, but they consume memory proportional to
the length of the input string, and so are also not practical.

re2c/lib/bench.cc

index cf4510a37c28841f25a51bcdef61e99e7bf2fe96..c17b852efaa43ad78a30f2e06e5f8d81b044921f 100644 (file)
@@ -124,10 +124,6 @@ int main()
     longstring[VERY_LONG - 1] = 0;
     bench(regexp, longstring, 1, true);
 
-    regexp = "((a?){1,10}(a)?)*";
-    memset(longstring, 'a', VERY_LONG);
-    bench(regexp, longstring, 1, true);
-
     regexp = "((((a)*))*|(((((a)))*))+)*";
     memset(longstring, 'a', VERY_LONG);
     bench(regexp, longstring, 1, true);
@@ -151,6 +147,16 @@ int main()
     string = "";
     bench(regexp, string, 1, false);
 
+    // Pathological case for constant-memory POSIX algorithms (includes TDFA).
+    // Takes quibic time in the size of counter. This is caused by quadratic-
+    // time computation of precedence matrix on each step (the number of TNFA
+    // states in the closure approaches TNFA size), multiplied by the length
+    // of compared histores (which also approaches TNFA size). Trie-based
+    // algorithms are not affected, but they consume memory proportional to
+    // the length of the input string, and so are also not practical.
+    regexp = "((a?){1,200})*";
+    bench(regexp, "a", 1, false);
+
     delete[] longstring;
     return 0;
 }