Closed Bug 1306450 Opened 8 years ago Closed 7 years ago

JavaScript TypedArray access in some cases too slow

Categories

(Core :: JavaScript Engine: JIT, defect, P3)

49 Branch
x86_64
Windows 7
defect

Tracking

()

RESOLVED FIXED

People

(Reporter: CoolCmd, Unassigned)

References

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0
Build ID: 20160922113459

Steps to reproduce:

open https://jsfiddle.net/CoolCmd/Leuootfs/
here 2 functions are tested: func1() and func2().
click 'run tests' button at right side.
wait for tests complete.
each test have ops/sec value, greater is faster.



Actual results:

func1() 100 (!) times slower than func2(). they differ only one line.
i think JIT has a bug.


Expected results:

func1() and func2() speed can differ, but not so much.
Component: Untriaged → JavaScript Engine: JIT
OS: Unspecified → Windows 7
Product: Firefox → Core
Hardware: Unspecified → x86_64
both functions called without providing parameter 'begin', thus following 'if' always executed:
if (begin === undefined)
{
	begin = 0;
}
My best guess about what's going on here is that in func2 our range analysis succeeds at eliminating checks that are still performed in func1.

Jandem, is this something we can fix? It seems quite likely to affect lots of code, because it's caused by the common pattern of checking for unset arguments and setting them to default values. FWIW, changing func1's signature to `function func1(begin = 0)` and removing the `if (begin === undefined)` also triggers it.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(jdemooij)
We should be falling back to an IC for func1, but we don't do that here because of 2 different Ion perf issues.

With the IC stub, func1 is about 8x (instead of 100x) slower than func2, there's more we can do at that point.
Depends on: 1306626
V8 also don't like code from comment #1, but his code 'only' 1.5 times slower.
can anyone explain why this slowdown happens? because 'begin' changes type from undefined to int? can this happens with normal var (not function parameter)?
this variant is fast:
var b = begin === undefined ? 0 : begin;
Depends on: 1307494
Depends on: 1307502
Priority: -- → P3
Nightly (55) now gets:

func1 x 24,606 ops/sec ±0.36% (90 runs sampled)
func2 x 24,402 ops/sec ±0.51% (93 runs sampled)

And Chrome Canary (61):

func1 x 11,875 ops/sec ±1.01% (92 runs sampled)
func2 x 11,732 ops/sec ±1.20% (90 runs sampled)

I'll mark this fixed, please file a new bug if you find other performance issues.
Status: NEW → RESOLVED
Closed: 7 years ago
Flags: needinfo?(jdemooij)
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.