Significant difference in performance of JSArrays vs TypedArrays when performing arithmetic in a loop

38 views
Skip to first unread message

Suraj Sharma

unread,
Feb 2, 2021, 11:46:26 PM2/2/21
to v8-dev

Hello everyone,

I was running a micro benchmark(attached at the bottom) and noticed something interesting.

There is a significant difference in performance  between TypedArray and regular JSArray when performing arithmetic in a loop,

When timing the function foo() on release build of d8 on x64 machine we get following result:

JSArray: 616 ms

TypedArray: 1261 ms

I did some investigation and found that we always perform an overflow check for loop variable i when using TypedArray irrespective of the value of length.

I have made some progress in addressing this issue, but need some help in putting some pieces together.

Here is the link summarizing my investigation.

PTAL

Thanks 

Suraj

foo.png


Jakob Kummerow

unread,
Feb 3, 2021, 1:32:57 PM2/3/21
to v8-dev
Isn't this an off-by-one error of sorts? I'm by no means an expert on Turbofan range analysis, but it seems that if TF realized that i is strictly less than the array length, then that would be enough to optimize away the overflow check on the increment?


--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-dev/c2c96e24-ce44-4afb-9a98-ab2829c9cae2n%40googlegroups.com.

Georg Neis

unread,
Feb 4, 2021, 12:16:54 PM2/4/21
to v8-...@googlegroups.com
I don't think so. If the typed array is large (length >= 2^31) then the (signed) overflow can and will happen when i = 2^31 - 1. [side note: even unsigned overflow (carry flag) would happen when i = 2^32 - 1, which the max length of 2^32 allows for.]

Suraj, I'll take a closer look at this when I find time and will comment in your document.

Thanks!
 Georg

Jakob Kummerow

unread,
Feb 4, 2021, 12:42:57 PM2/4/21
to v8-dev
Oh, right. It was my thinking that was off by one, twice: on the signed bit length, and on the maximum value! Sorry for any confusion caused.

Suraj Sharma

unread,
Feb 4, 2021, 3:41:43 PM2/4/21
to v8-dev
Precisely! :) Thanks Georg and Jakob for the feedback.
Feel free to reach out if you need any clarification or more information :)

Thanks
Suraj
Reply all
Reply to author
Forward
0 new messages