New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 651228 link

Starred by 3 users

Issue metadata

Status: Fixed
Owner: ----
Closed: Jul 17
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Feature



Sign in to add a comment

JavaScript's method Uint8Array.copyWithin() extremely slow

Reported by cool...@gmail.com, Sep 28 2016

Issue description

UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0

Steps to reproduce the problem:
1. open https://jsfiddle.net/CoolCmd/two1qzfn/3/
2. click 'run' in the upper left corner
3. click 'run tests' button in the right half of the screen
4. wait for 3 tests complete
5. each test have ops/sec value, greater is faster

What is the expected behavior?
'copyWithin' must be faster than 'new Uint8Array' and 'subarray'.

What went wrong?
'copyWithin' 300 times slower than 'new Uint8Array'!

the irony is that the copyWithin created to accelerate copying...
in the Firefox this method 5 times faster.

Did this work before? No 

Chrome version: 53.0.2785.116 m (64-bit)  Channel: stable
OS Version: 6.1 (Windows 7, Windows Server 2008 R2)
Flash Version: Shockwave Flash 23.0 r0
 

Comment 1 by woxxom@gmail.com, Sep 28 2016

It uses js shim/polyfill that copies values in a loop instead of using memcpy properly.

v8 issue: https://bugs.chromium.org/p/v8/issues/detail?id=3578
CL:       https://codereview.chromium.org/1131113002

Comment 2 by cool...@gmail.com, Sep 29 2016

typed arrays frequently used for relatively large (for JavaScript) pieces of data. thus creating primitive shims for 'low-level' methods (like copyWithing, fill, indexOf, slice) is very bad idea!
Components: -Blink Blink>JavaScript

Comment 4 by cool...@gmail.com, Sep 29 2016

https://jsfiddle.net/CoolCmd/two1qzfn/ - copyWithin()
https://jsfiddle.net/CoolCmd/2jsLmync/ - slice()
https://jsfiddle.net/CoolCmd/1324mkLr/ - fill()
even without asm my shims considerably faster than native shim.

Cc: littledan@chromium.org adamk@chromium.org
Labels: -Type-Bug Type-Feature
Great to see that. If you want to contribute to V8 to put these faster versions in the browser, you can see the steps here: https://github.com/v8/v8/wiki/Contributing . I'm happy to review a patch here.

Comment 8 by cool...@gmail.com, Oct 1 2016

> If you want to contribute to V8
sorry, i don't think it is good idea.
contributor must know V8 internals, macros, parameters validation, etc.
this is the main difficulty. my code from above links is trivial...
Coolcmd, could you say more about the use cases your have for these methods, to motivate putting in the work on our end to optimize them? It's possible to bang on just about anything and make it faster against some benchmark. I implemented these methods in a deliberately simple way to minimize system complexity absent particular use cases which required higher performance.

Comment 10 by cool...@gmail.com, Oct 1 2016

personally i use typed arrays to remux video from TS to MP4 (Chromium don't support TS). also typed arrays used by WebGL and asm.js. by definition, typed arrays most suitable for manipulating large pieces of data: parsing file or data from device. in all other situations normal arrays more preferable. yes, i think typed array don't used on most sites.

Comment 11 by cool...@gmail.com, Oct 1 2016

i am not sure how widely used method indexOf()...

Comment 12 by woxxom@gmail.com, Oct 1 2016

> It's possible to bang on just about anything and make it faster against some benchmark

copyWithin case with 1000x speedup seems to be unique, far from "just about anything" which could be fit within 2x, so why not give it special treatment...

Comment 13 by cool...@gmail.com, Oct 1 2016

about methods. in my project i use copyWithin() and slice() for copying parsed data. fill() and indexOf() i added, because they used in C++ for buffer manipulation (memcpy, memcmp, memset). for example, asm.js don't support strings, and to find substring TypedArray.prototype.indexOf() called instead of String.prototype.indexOf(). copyWithin() widely used in asm.js, because asm.js use 1 buffer for all of its data.

Comment 14 by woxxom@gmail.com, Oct 1 2016

> I implemented these methods in a deliberately simple way

However, the runtime complexity of your implementation is HUGE since js is an interpreted language. As we all know, built-in methods should always be used whenever possible, for example, Array.indexOf finds a plain value much faster compared to "deliberately simple way" of doing millions of iterations in js code comparing each plain value. Likewise, in the case of copyWithin using a typed array constructor to accomplish the task in one js operation is a much more natural choice.
Status: Available (was: Unconfirmed)
Project Member

Comment 17 by sheriffbot@chromium.org, Jul 16

Labels: Hotlist-Recharge-Cold
Status: Untriaged (was: Available)
This issue has been Available for over a year. If it's no longer important or seems unlikely to be fixed, please consider closing it out. If it is important, please re-triage the issue.

Sorry for the inconvenience if the bug really should have been left as Available.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Because V8 issue was fixed, this issue can be closed.
Status: Fixed (was: Untriaged)

Sign in to add a comment