User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Build Identifier: Rhino v126.96.36.199 Executing s.replace(a, b) is ten times slower than in rhino 1.5.3. Note that when a is a match inside s, then execution time is the same. But if a isn't there, then the performance is ten folds slower. Reproducible: Always Steps to Reproduce: var a = new Array(); for (var i=0; i<10000; i++) a[i] = 'A'; var s = a.join(''); var t = java.lang.System.currentTimeMillis(); //the test: s = s.replace('BBB', 'AAA'); s = s.replace('BBB', 'AAA'); s = s.replace('BBB', 'AAA'); s = s.replace('BBB', 'AAA'); s = s.replace('BBB', 'AAA'); java.lang.System.out.println('time: '+(java.lang.System.currentTimeMillis()- t));
I will look at it
Created attachment 138417 [details] [diff] [review] Less calculations in inner loops in regexps It looks like the optimization for regexps starting with literal character to look first for that character actually made thinks worse probably due to too often recalculations of invariant conditions at the beginning of each NativeRegExp.executeREBytecode invocation. The patch reorganize the code to move this recalculations outside the main loop in NativeRegExp.matchRegExp and this refactoring speedup matching by factor of 10 for trivial regexps.
Created attachment 138472 [details] [diff] [review] Patch update I added few more inlining/refactoring to gain in speed compared with the previous patch.
I committed the last fix
With the last tip committed Rhino CVS is 2 times faster then 1.5R3 with the original test case.
Trageting as resolved against 1.5R5