Closed Bug 34571 Opened 25 years ago Closed 25 years ago

Concatenation of string variables slow compared to strings themselves

Categories

(Core :: JavaScript Engine, defect, P3)

x86
Windows 98
defect

Tracking

()

VERIFIED INVALID

People

(Reporter: warnckew, Assigned: pschwartau)

Details

(Keywords: perf, testcase)

Attachments

(1 file)

I'll be uploading a test case with various tests of string concatenation. Mozilla (build 2000040308) shows good performance with all the ones that uses strings directly, e.g. "string1" + "string2". it's the last three it has problems with, they use string variables (e.g. var1 + var 2) in the concatenation. try it out for yourselves. all numberical values shown in the form fields is the execution time in millseconds. the four tests on the left hand side, and the 2 at the top on the right hand side finished in around 1650ms on my P3/450. this is just the same speed as Netscape Comm 4.72. On the last three tests on the right hand side NC4.72 uses 7000ms, 10000ms and around 4500ms respectively, while Mozilla suddenly uses 10000ms, 14750ms and 5500ms on the same three tests. I'm slightly surprised by this sudden large increase in execution time. the test results are very positive compared to IE5.01 though, except for the three tests with variables in them. the 4 tests on the left hand side, from top to bottom, finish in around 5.5s, 9s, 12.5s and 16s in IE5.01. in other words, a nearly linear increase in usage for each string that gets added. the two top tests on the right hand side finish in around 9.3s and 20s, a _huge_ difference from both Mozilla and Communicator. the last three tests, with variables, execute at just about the same speed as Communicator though (the last one actually about a second faster).
adding keyword 'testcase' as per bugathon guidelines
Keywords: testcase
--> phil, would you try running against the shell to see if this is embedding related or an engine specific issue?
Assignee: rogerl → pschwartau
Confirming. The last three cases currently crash Mozilla - bug 31925 filed. Gerv
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: perf
Note - there is a transposition above: the related bug is 39125, not 31925.
Thank you for these tests !!! I have checked this issue with the JavaScript Engine team. Concatenation of literal strings is faster than that of variables because the JavaScript compiler has been optimized. Concatenations get turned into byte code by the compiler something like this: SCRIPT BYTE CODE str = 'Hello' + var ===> Add 'Hello', var, str (i.e. add 'Hello' and var, and put the result into str) str = 'Hello' + ' there' ===> Mov 'Hello there', str (i.e. put 'Hello there' directly into str) The compiler is optimized to realize that in the literal concatenation, str cannot be anything other than 'Hello there', so it proceeds to put this value directly into str. If the compiler were not optimized, all additions would be equally slow as addition of variables … So this bug as stated must be marked as invalid. However, the reporter's test cases have been extremely helpful, and have uncovered an out-of-memory issue filed as bug 39125. Also related are bug 2235 and bug 3649. For the record, here are times in milliseconds I recorded for the reporter's own tests. I was testing the JavaScript from the JavaScript shell, pulled and built from the Mozilla cvs repository on 06/01/00, rather than from the Mozilla browser embedding. Note that the time growth is approximately linear as we increase the number of iterations: Concatenation 10^3 iterations 10^4 10^5 10^6 two small strings 0 16 250 2453 three small strings 0 16 250 2453 four small strings 0 16 250 2453 five small strings 0 16 250 2453 two large strings 0 16 250 2453 three large strings 0 16 250 2469 two strings and a variable 0 63 688 out of memory two strings and two variables 0 94 969 out of memory two variables 0 47 469 out of memory
Status: NEW → RESOLVED
Closed: 25 years ago
Resolution: --- → INVALID
Note: my OS for these results was WinNT 4.0 (SP5)
Thanks for the explanation Phil. I'm glad I could be of some help, even though this actual bug is invalid. Seems like I've discovered an area where all browsers take a performance hit, something I'll keep in mind for later work.
Problems with browsers in general not Mozilla marking as Verified.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: