I'm experiencing some strange performance issues related to the
Pattern and Matcher classes in java.util.regex.


where 'myTerms' is a String[]

for (int a = 0; a < myTerms.length; a++) {
Pattern p = Pattern.compile(" *" + myTerms[a] + " +");
Matcher m = p.matcher(<some string>);
m.find();
}

when myTerms.length is big.... I see strange "stalls and
accelarations" in the performance over time. Anyone care to comment
on why that might happen. The stalls I see in performance are
reproducible and always of this form:


|
|
| * * * *
| *
| * * * * * *
| *
| *
|*
|------------------------------

where x-Axis is time and Y-axis is records processed. I'm pretty sure
the slow-downs are NOT data driven, b/c the the areas that look like
they are flat actually have a small slope (the implication being that
many records are processed during that time - so the stall isn't just
on one particularly difficult pattern. Also - all the patterns have
the same regex quality - i.e. the strings in myTerms aren't regular
expressions themselves...