Bug 12648 - 9A241: JavaScript RegExp 25-30x slower than on 10.4.7
Summary: 9A241: JavaScript RegExp 25-30x slower than on 10.4.7
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 420+
Hardware: Macintosh OS X 10.4
: P1 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2007-02-06 23:21 PST by Maciej Stachowiak
Modified: 2007-02-07 03:51 PST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maciej Stachowiak 2007-02-06 23:21:24 PST
2006-08-18 03:31:49 Keisuke Hara:
* SUMMARY
JavaScript RegExp in Leopard9A241 seems to be slower than Chardonnay8G1165 on my machine (PowerMac G5 2.5GHz dual).

Attached Xcode project to test this problem. When running it and pressing "Load HTML via JavaScript" button, it loads HTML via XMLHttpRequest(), modifies link URLs using RegExp, and logs elapsed time for modifying text as "process text time = XX ms" to debugger console. (WikipediaSupport.js)

When I ran this application on Chardonnay8G1165, elapsed time is 3 ms, but the same task took about 70 ms on Leopard9A241.

2006-08-21 11:35:21 Alice Liu:
Hi Keisuke,  I can build your project on Leopard 9A241 but not 10.4.7 8J135.  if your test case just involved XMLHTTPRequest(), you should be able to create a standalone HTML file with javascript to test your bug, right?  Also, where is the elapsed time logged to? I'm looking in various logs in Console.app and I don't see any output.  The best way to proceed with this bug is to write a standalone test file that we can open with a browser.  If you want to log to the JS console in Safari, use window.console.log("output").  

2006-08-22 18:20:33 Keisuke Hara:
The attached project is made for my another investigation task, so should not be most suitable for reproducing this issue, sorry. The log from JavaScript is redirected to NSLog() in the test application, so it should be written to Console.app (or Run Log /Debugger Console if running in Xcode, of course).

Anyway, I'll make a standalone HTML file to be loaded into Safari.

2006-08-22 19:04:15 Keisuke Hara:
Created and attached HTML and JavaScript file (TestFiles.zip). Please load Test.html file into Safari. I used both window.console.log() and alert() to show the result. The result on my machine, 9A241/8G1165 = 60/2.

2006-08-23 12:51:40 Alice Liu:
Thanks for the test file!

2006-08-25 15:58:01 Stephanie Lewis:
Using his test file I got ~8 seconds in Tiger vs ~89 seconds in Leopard 9A250

2006-08-29 10:26:40 Alice Liu:
Safari BRB Reviewed 

2006-10-11 09:54:51 Matt Drance:
I'm seeing ~20x slower testing one of my Dashboard widgets in nightly WebKit on Tiger; I'll reduce the case and attach it here.

2006-10-11 10:25:35 Matt Drance:
Attached... takes 23ms in Safari 2.0.4 (419.3); 1867ms in WebKit-SVN-16968.

2006-12-15 19:26:02 Stephanie Lewis:
Still occurs in Leopard 9A325

2006-12-20 16:09:51 Darin Adler:
The reason this happened is because we turned on NO_RECURSE, because otherwise regular expressions can overflow the stack.

In the NO_RECURSE code path there are many uses of longjmp, and according to my profiling longjmp is quite slow.

Perhaps to fix this we can figure out a way to make NO_RECURSE work without using longjmp.

2006-12-20 16:13:34 Darin Adler:
The change that turned NO_RECURSE on was revision 14435 , done to fix an incompatibility with Yahoo <http://bugs.webkit.org/show_bug.cgi?id=8870>.

2006-12-21 12:26:10 Darin Adler:
I think we might be able to replace the longjmp with a switch statement and gotos.

2006-12-21 12:29:10 Darin Adler:
There seem to be 53 different uses of the RMATCH macro (oof).

2007-01-03 22:22:17 Geoff Garen:
I looked at using Mozilla's jsregexp.c today. It doesn't look terribly complicated to port. However, they're still 3-5X slower than 10.4.7 (in Firefox). That finding was also confirmed in <rdar://problem/4519589>.

2007-02-06 08:35:24 Darin Adler:
I found a great solution! We can use gcc's computed goto. I have it coded already, but I haven't done performance testing yet.

2007-02-06 09:37:49 Darin Adler:
I've got it now 6% slower instead of 2000% slower. Still working on it.

2007-02-06 09:58:39 Darin Adler:
Test case is now 15% faster instead of 2000% slower. But other regular expression tests might end up slower.

<rdar://problem/4687840>
Comment 1 Maciej Stachowiak 2007-02-06 23:33:22 PST
This has been fixed.
Comment 2 David Kilzer (:ddkilzer) 2007-02-07 03:51:40 PST
Committed by darin in r19434.