Closed Bug 501230 Opened 15 years ago Closed 15 years ago

TM: fast path for String.toString

Categories

(Core :: JavaScript Engine, defect, P2)

defect

Tracking

()

RESOLVED FIXED
mozilla1.9.2a1

People

(Reporter: gal, Assigned: brendan)

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file, 2 obsolete files)

      No description provided.
Attached patch patch (obsolete) — Splinter Review
This does GetMethod twice potentially, but only if the object is of StringClass, which should be safe.
Assignee: general → gal
This path is hit heavily in dromaeo JS tests >> string tests >> charAt test.
100x that Dromeo test

without the patch: 643
with the patch: 414

(smaller is better)
The 643 is with Bug 501254 applied. Without that we get 1488, which is slower than interpretation (1202).
Attachment #385875 - Flags: review?(brendan)
"100x that dromeo test" => running that test 100 times (it runs too short originally to properly measure it)
You can't argue about getMethod called twice being "safe" in the presence of user-defined getters. By the book, toString should be got only once.

Suggest pushing the optimization down into js_DefaultValue.

/be
I thought its safe because of the js_StringClass check. Could you briefly explain why thats not the case? (I believe you its not, I just don't understand why not ;)

I will push this further down and eliminate the redundant getMethod.
js> save = String.prototype.toString                                
function toString() {
    [native code]
}
js> String.prototype.__defineGetter__('toString', function(){++effectCount; return save.apply(this, arguments)})
js> effectCount=1
1
js> s = new String('hi')
hi
js> s
hi
js> effectCount
2

You don't know what the getter might do. It could have arbitrary effects. The spec says toString is tried once. The example above shows this. With your patch if I'm not mistaken the effectCount would be 4 at the end.

/be
Attachment #385875 - Flags: review?(brendan)
Attached patch proposed alterna-patch (obsolete) — Splinter Review
Attachment #385875 - Attachment is obsolete: true
Attachment #388833 - Flags: review?(gal)
Someone could set String.prototype.__proto__ = null or s = new String("hi"); s.__proto__ = null -- that would be just mean, but it's allowed.

/be
Attachment #388833 - Attachment is obsolete: true
Attachment #388835 - Flags: review?(gal)
Attachment #388833 - Flags: review?(gal)
Attachment #388835 - Flags: review?(gal) → review+
Assignee: gal → brendan
Status: NEW → ASSIGNED
OS: Mac OS X → All
Priority: -- → P2
Hardware: x86 → All
Target Milestone: --- → mozilla1.9.2a1
http://hg.mozilla.org/tracemonkey/rev/9a626a99c67c

/be
Whiteboard: fixed-in-tracemonkey
Nice, what's the win like?

(Wouldn't we rather just emit a tiny bit of LIR here?  Guard on shape, deref a couple of pointers, Bob's your screaming CPU pipeline?)
(In reply to comment #12)
> Nice, what's the win like?
> 
> (Wouldn't we rather just emit a tiny bit of LIR here?  Guard on shape, deref a
> couple of pointers, Bob's your screaming CPU pipeline?)

There are lotsa ways to reach OBJ_DEFAULT_VALUE that won't go through an imacro being recorded for JITting. String objects are rare birds outside of Dromaeo, so any JIT-only optimizations should go in a later bug, if we feel the need.

Why is Dromaeo creating String wrappers? Dunno. Anyone?

/be
(In reply to comment #12)
> Nice, what's the win like?

Andreas said strictly better than the win measured in comment 3 but I didn't hear actual numbers.

/be
John, see comment 13 para 2. Thanks,

/be
http://hg.mozilla.org/mozilla-central/rev/9a626a99c67c
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: