Bug 15835

Summary: Switch List to Vector (.5% speedup)
Product: WebKit Reporter: Geoffrey Garen <ggaren>
Component: JavaScriptCoreAssignee: Geoffrey Garen <ggaren>
Status: RESOLVED FIXED    
Severity: Normal    
Priority: P2    
Version: 523.x (Safari 3)   
Hardware: Mac   
OS: OS X 10.4   
Attachments:
Description Flags
Patch darin: review+

Description Geoffrey Garen 2007-11-04 15:49:14 PST
Patch coming.
Comment 1 Geoffrey Garen 2007-11-04 15:49:30 PST
Created attachment 17039 [details]
Patch
Comment 2 Darin Adler 2007-11-04 16:44:33 PST
Comment on attachment 17039 [details]
Patch

The best idiom for iterating a vector is to use indices and not bother with iterator objects at all. I believe it's faster than the iterator version, and certainly more readable!

But for speed, you'd want a version that doesn't do a range check each time.

r=me (as is -- those comments above are "food for thought")
Comment 3 Eric Seidel (no email) 2007-11-05 13:42:22 PST
Nice!  Sad it was so little...
Comment 4 Geoffrey Garen 2007-11-05 13:47:05 PST
Committed revision 27448.

Iteration by index would certainly be more readable. I think we could do that if we made "return undefined if I'm past the end" a special-case function instead of the default behavior of operator[]. (Hopefully we could do that without introducing subtle regressions!)

Still, I worry that iteration by index might be slightly slower, based on this check-in by Maciej: http://trac.webkit.org/projects/webkit/changeset/27339. It seems like using a pointer directly into the VectorBuffer can be faster than using an integer offset into the Vector, which translates into a pointer into the VectorBuffer. (Maybe the compiler can optimize that translation out, though.)
Comment 5 Geoffrey Garen 2007-11-05 13:47:32 PST
Changeset 27448.