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

Issue 648154 link

Starred by 1 user

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Linux , Mac
Pri: 2
Type: Bug



Sign in to add a comment

First execution of function is faster than sequent

Reported by andreabo...@gmail.com, Sep 19 2016

Issue description

UserAgent: 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.
 
by writing: "Firefox, safari and IE have constant behaviour in this" i mean that the other browsers takes always the same time to execute.
Cc: durga.behera@chromium.org
Components: Platform>DevTools
Labels: Needs-Feedback
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.
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.
Screen Shot 2016-09-20 at 1.38.46 PM.png
153 KB View Download
Components: -Platform>DevTools -Blink Blink>Canvas
Owner: xidac...@chromium.org
Status: Assigned (was: Unconfirmed)
Investigating
Cc: bmeu...@chromium.org xidac...@chromium.org jochen@chromium.org
Components: -Blink>Canvas Blink>JavaScript
Labels: -Needs-Feedback
Owner: ishell@chromium.org
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?
Labels: OS-Linux
Oh, I forgot to mention, comment#6 is observed on Linux.

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.
any news for this matter? some code path are still heavily slowed down after first run
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