Closed Bug 1041781 Opened 11 years ago Closed 11 years ago

IonMonkey: Optimize constant charCodeAt.

Categories

(Core :: JavaScript Engine: JIT, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla34

People

(Reporter: djvj, Assigned: djvj)

Details

Attachments

(1 file, 1 obsolete file)

I was taking a stab at writing an efficient tokenizer in JS over the weekend, and I realized that there's no efficient way of matching input codepoints against pattern codepoints that are both constant and legible. For example: var c = this.nextChar(); if (c == 'x'.charCodeAt(0)) { ... } Is slow and forces a string lookup. Putting the property on an object is better, but it forces a property load. Neither case allows the placement for a constant number that is clearly derived from its character representation. Ion can optimize these just fine. MCall("charCodeAt", MConstantString, MConstantInt32) can reduce to a constant int32 result. This lets us use C.charCodeAt(0) as a shorthand for the integer code for a char C.
Attachment #8459844 - Flags: review?(hv1989)
Comment on attachment 8459844 [details] [diff] [review] optimize-constant-charcodeat.patch Review of attachment 8459844 [details] [diff] [review]: ----------------------------------------------------------------- Oh that is sad we can't use GVN for this. Since we cannot access JSString from another thread. Though I have some questions: 1) Can you move this to under the checks if inlining will work or not. So after callInfo.setImplicitlyUsedUnchecked(); 2) Can you fallback to MCharCodeAt instead of returning InliningStatus_NotInlined;
Attachment #8459844 - Flags: review?(hv1989)
Comments addressed. Running on try: https://tbpl.mozilla.org/?tree=Try&rev=81060beb8d90
Attachment #8459844 - Attachment is obsolete: true
Attachment #8465516 - Flags: review?(hv1989)
Comment on attachment 8465516 [details] [diff] [review] inline-constant-charcodeat.patch Review of attachment 8465516 [details] [diff] [review]: ----------------------------------------------------------------- Nice. Using a new function is even better. Now I retract one of the comments I made. Please move the callInfo.setImplicitlyUsedUnchecked();. Because all functions in there do: function () { check_if_can_inline callInfo.setImplicitlyUsedUnchecked(); inline code } ::: js/src/jit/MCallOptimize.cpp @@ +1178,5 @@ > MIRType argType = callInfo.getArg(0)->type(); > if (argType != MIRType_Int32 && argType != MIRType_Double) > return InliningStatus_NotInlined; > > callInfo.setImplicitlyUsedUnchecked(); Can you move this under inlineConstantCharCodeAt() @@ +1208,5 @@ > + return InliningStatus_NotInlined; > + > + if (!callInfo.getArg(0)->isConstant()) > + return InliningStatus_NotInlined; > + + callInfo.setImplicitlyUsedUnchecked();
Attachment #8465516 - Flags: review?(hv1989) → review+
Assignee: nobody → kvijayan
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla34
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: