If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

String.replace is much slower than in rhino 1.5.3

RESOLVED FIXED in 1.5R5

Status

Rhino
Core
RESOLVED FIXED
14 years ago
14 years ago

People

(Reporter: yaar schnitman, Assigned: Igor Bukanov)

Tracking

other
1.5R5
x86
Windows XP

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Reporter)

Description

14 years ago
User-Agent:       Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
Build Identifier: Rhino v1.5.4.1

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));
(Assignee)

Comment 1

14 years ago
I will look at it
Assignee: nboyd → igor
(Assignee)

Comment 2

14 years ago
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.
(Assignee)

Comment 3

14 years ago
Created attachment 138472 [details] [diff] [review]
Patch update

I added few more inlining/refactoring to gain in speed compared with the
previous patch.
Attachment #138417 - Attachment is obsolete: true
(Assignee)

Comment 4

14 years ago
I committed the last fix
Status: NEW → RESOLVED
Last Resolved: 14 years ago
Resolution: --- → FIXED
(Assignee)

Comment 5

14 years ago
With the last tip committed Rhino CVS is 2 times faster then 1.5R3 with the
original test case.
(Assignee)

Comment 6

14 years ago
Trageting as resolved against 1.5R5
Target Milestone: --- → 1.5R5
You need to log in before you can comment on or make changes to this bug.