First execution of function is faster than sequent
Reported by
andreabo...@gmail.com,
Sep 19 2016
|
||||||
Issue descriptionUserAgent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 Steps to reproduce the problem: 1. Open this fiddle http://jsfiddle.net/emeagcnx/13/ 2. Open the console to see the logs 3. read this issue tracker https://github.com/kangax/fabric.js/issues/2442 What is the expected behavior? Function should take more or less always the same time. What went wrong? The function takes some ms to execute first time and lot more executing the other times. I know this is not a simple js script and depends on fabricjs but the code is straight forward and the dev tools screenshot in the issue tracker show that something is going wrong. Did this work before? No Chrome version: 53.0.2785.116 Channel: stable OS Version: OS X 10.11.5 Flash Version: Shockwave Flash 23.0 r0 Firefox, safari and IE have constant behaviour in this.
,
Sep 20 2016
In the console getting the error as "GET https://www.deltalink.it/andreab/fabric/fabric.js net::ERR_INSECURE_RESPONSE" on Mac 10.11.6 using stable 53.0.2785.116. Could you please elaborate more what has to be looked for further triage it.
,
Sep 20 2016
I m very sorry, something went wrong when saving fiddle. http://jsfiddle.net/emeagcnx/20/ fiddle updated. Attach screenshot of console with filter timing: As you see first time the functions take 115ms, then 600ms. In other browsers does not happen.
,
Sep 20 2016
,
Sep 21 2016
Investigating
,
Sep 21 2016
I have some investigation.
I found that inside the fabric.js, there is a function applyTo around line 19000, and inside that function there is a giant for loop look like this:
for (var y = 0; y < sh; y++)
for (var x = 0; x < sw; x++)
...
for (var cy = 0; cy < side; cy++)
for (var cx = 0; cx < side; cx++)
...
I put a timer surrounding this entire for loop block, and it takes about 150ms in the first time, and 270ms in the second time. I suspect there is some kind of v8 de-optimization.
Aside from that, I tried reverting this CL locally:
https://codereview.chromium.org/2330063002
and what I observe is that the entire for loop block takes 42ms in the first time, and 173ms in the second time, which is 100ms less everytime.
I am adding the author of the above CL, could you please take a look?
,
Sep 21 2016
Oh, I forgot to mention, comment#6 is observed on Linux.
,
Sep 21 2016
That big cycle is a convolution filter. so while the 2 external loops are for rows and columns in the image and read the image as a buffer, the internal 2 loops are the convolution matrix and read data in the current line and also in the upper and lower lines of image. i imagine this can confuse some caching logic. Firefox was once affected but they solved one day. I do not know in wich revision, maybe is understandable by the dates in the issue tracker of fabricjs.
,
May 14 2017
any news for this matter? some code path are still heavily slowed down after first run
,
Jun 13 2017
http://jsfiddle.net/emeagcnx/30/ i updated the fiddle since the linked lib ahd an api change that broke it. The situation improved a bit, i m unsure if is chrome 59 and the underling changes. First execution ~95ms, after ~170ms. This is a 2x slowdown vs a 4x-5x slowdown we had before. |
||||||
►
Sign in to add a comment |
||||||
Comment 1 by andreabo...@gmail.com
, Sep 19 2016