Closed
Bug 727833
Opened 14 years ago
Closed 7 years ago
photoraster.com is much slower in Firefox then in Chrome
Categories
(Core :: Graphics: CanvasWebGL, defect)
Tracking
()
RESOLVED
INCOMPLETE
People
(Reporter: david.levinsky, Unassigned)
References
()
Details
(Whiteboard: webgl-perf)
Attachments
(1 file)
|
709 bytes,
text/html
|
Details |
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.1) Gecko/20100101 Firefox/10.0.1
Build ID: 20120208060813
Steps to reproduce:
Visit photoraster.com, click "try it now" button, open some image (e.g. Mona Lisa), click at "Move" tool (black arrow), and try to move with displayed image.
Actual results:
Image moves very laggy.
Expected results:
Image is moving much more fluently in chrome. This is not only example. Chrome is much faster in almost every way. Maybe it is related to WebGL implementation or garbage collector. I don't know. I am not able to pinpoint exactly what is responsible for that. I like Firefox browser and I hope that we will be able to find the cause.
Comment 1•14 years ago
|
||
This looks more like a flash app but you get an error about missing webgl support if you try this with for example Opera11.61. The seeps looks ok for me with Seamonkey trunk and win7 but I can't compare with any webkit browser.
Component: Untriaged → Graphics
Product: Firefox → Core
QA Contact: untriaged → thebes
| Reporter | ||
Comment 2•14 years ago
|
||
I am creator of this application. This application is purely based on javascript and WebGL. Flash is used only for saving files to local computer. My point is that there is big difference in performance between firefox and chrome. And this is big mystery for me, because as far as I know both firefox and chrome are using ANGLE for emulation of OpenGL ES 2.0. So in theory there should not be big difference in speed between these two browsers. Unless one of them implements something differently. My question is what is it? Is it bug or is there reason for it? Is it possible to overcome it somehow? I know that chrome has faster javascript but it seems that this difference in performance is not only related to javascript, there has to be something else. Thank you for your help.
Comment 3•14 years ago
|
||
So what I see on Mac is that there's code calling drawElements and various related things off a setTimeout, and separate code calling clear() and drawElements and whatnot off mouse events. I assume that's expected?
| Reporter | ||
Comment 4•14 years ago
|
||
If you are pointing to the fact that this application is very resource consuming, then yes, you are true. In fact this application is one of most complex javascript/WebGL application of these days. But this also makes it very interesting case study. Imagine very complex and processing hungry application (something like photoshop) which runs in javascript. Where most of heavy weight processing is solved by GPU. And surprisingly it works very well (on my old PC). It already can do image processing which other flash application can only dream off. It only needs little faster graphics card. Unfortunately most notebooks and Macs do not have GPU powerful enough. I was hoping that you have have some profiling tools which helps us to pinpoint why is there such difference in performance between these two browsers. I realize that my bug report is very general to be solved. OK, I will investigate and I will let you know when I find something which is more straight forward for debugging. You can close this bug report.
| Reporter | ||
Updated•14 years ago
|
Component: Graphics → Canvas: WebGL
Comment 5•14 years ago
|
||
Actually, my question was actually exactly what I asked: is it expected that work will happen both directly off mouse events and off a timeout in this case? As in, it's not the same work accidentally being done twice?
Past that, I did in fact run a profiler on this. I have the profile up right now. But making sense of it would be a lot easier if I had more of an idea of what your script is doing on purpose and what might be an accident, hence the questions...
| Reporter | ||
Comment 6•14 years ago
|
||
Sorry, for misunderstanding. Yes it is expected. Mouse events should only generate internal events. Internal events are processed together during "tick" event. Only exception is custom drawn mouse cursor and area under this cursor which is in some cases drawn once per mouse event and once per "tick" event. This can cause some performance penalty. I will optimize it in the future. I did some control logs for events and events processing and it seems to work as expected and there is no difference in precessing events between firefox and chrome.
I think that main problem is somewhere in WebGL implementation. I did some profiling both in firefox (firebug profiler) and Chrome and there are results (under relatively same conditions):
Firefox Chrome
--------------------------------------------
utGLRect 23.7% | 5.45%
utGLGenerateMipmaps 15.67% | 0.01% !!!!!!!!
utGLSetSampler 5.28% | 0.69%
utGLDrawFilledTRect 5.2% | 0.42%
utGLUseShader 3.74% | 0.55%
utResizeViewport 3.49% | 0.43%
utGLClearScreen 2.89% | 0.16%
...
Comment 7•14 years ago
|
||
For what it's worth, I see about 30% of my CPU time spent doing JS+WebGL from a timeout, but I see 52+% of my CPU time spent doing JS+WebGL directly off a mouse event... So in my case see a _lot_ of work done directly during the mouse event, which doesn't sound like your description...
This all apart from whatever is happening with the WebGL, of course. For what it's worth, about 25% of my execution time is JS, not WebGL.
Status: UNCONFIRMED → NEW
Ever confirmed: true
| Reporter | ||
Comment 8•14 years ago
|
||
You are right. My description in previous post was incorrect. During mouse events is scanned UI (javascript intensive). I also do screen redraw related to mouse cursor (javascript + WebGL intensive). I am working on elimination of this this redundant screen redraw. Scan of UI is done only during mouse event and not during "tick" event. I discovered one cause of slow WebGL performance in FF. It was caused by gl.flush(). This command was placed in "tick" event. Fortunately this command is no longer necessary to correct function of application. I also discovered that there is difference in how events are generated in browsers.
I am using this function for generating "tick" event:
window["requestAnimFrame"] = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(/* function FrameRequestCallback */ _callback, /* DOMElement Element */ _element) {
window.setTimeout(_callback, 1000/60);
};
})();
Chrome calls this function regularly no matter what mouse events occur at the same time. Firefox seems to work differently. FF calls this function only in case that there is no mouse event.
This explains why application appears so laggy during some operations. This also explains why I redraw cursor during mouse event.
When I call "tick" function during mouse events then application works much better in FF (but slower in Chrome). I will have to brunch code for each browser or do some checks how much time passed between ticks.
Thanks Boris
Comment 9•14 years ago
|
||
> Chrome calls this function regularly no matter what mouse events occur at the same time.
> Firefox seems to work differently. FF calls this function only in case that there is no
> mouse event.
That's very odd. Unless the mouse event handlers are taking more than 16ms to run, the animation callback should be firing every 16ms. Do you see the "not firing" behavior if the mouse event handler does nothing?
I'd really appreciate you not making the code do different things in different browsers at least until we're done investigating here... It's really hard to debug code that keeps changing.
| Reporter | ||
Comment 10•14 years ago
|
||
>Do you see the "not firing" behavior if the mouse event handler does nothing?
No.
It seems to be related to how much time takes event. When I do not use any kind of tool in application then mouse move event takes about 2.5ms (Chrome 1.5ms). During that time "tick" events are generated very well. When I use "move" tool then mouse move event takes about 22ms (Chrome 4ms). During that time "tick" events are not generated.
Fact that there is difference between how much takes mouse event with tool and without tool is caused by some image processing which I do immediately during event. Which is actually opposite of what I claimed before and I really shame for this. I did not know about that and it was pretty well hidden.
What kind of profiler are you using? Is it possible to use same profiler as you are using?
Comment 11•14 years ago
|
||
> When I use "move" tool then mouse move event takes about 22ms (Chrome 4ms). During that
> time "tick" events are not generated.
JS is run-to-completion; no new event delivery while your code is running. That's expected.
> What kind of profiler are you using? Is it possible to use same profiler as you are
> using?
Sure, if you have a Mac with OS 10.6 on it. I'm using Shark, with an optimized build of Firefox with symbols. Other OSes have other profiling options, of course. Note that I'm using a C++ profiler; To figure out what's going on in the script then requires mapping back from the C++ backend calls to what the script might be doing.
In any case, it sounds like we're on the same page now. Let's focus on what makes the mouse event processing so slow.
Inside the mouse event handler, time is spent about like this (all percentages are percentages of the total event handler time, and this is still on Mac):
22% JavaScript execution
23% drawElements() calls on the rendering context; this is largely
glDrawElements_ACC_Exec and glDrawElements_Exec.
21% clear() calls on the rendering context (mostly glClear_Exec).
11% uniformMatrix_x_fv() calls (about half typed array creation and half
UniformMatrix4fv_array); I assume you could speed this up by actually passing in
typed arrays, right?
6% generateMimMap on the rendering context
4% uniform_x_fv() calls. Again, this is not being passed typed arrays.
3% bindTexture
3% bindFrameBuffer
2% activeTexture
and then a long tail of minor stuff, but we have 95% accounted for already.
I wonder what this looks like on Windows...
If you have a version of this page that logs the event durations, could I take a look at that? That would at least give me some idea how the JS time I'm seeing might look for you.
Also, if it's possible to have your handler run all the JS it runs but not make any GL calls (might be hard if you use the results of some of those calls, I know), it would be interesting to time how long that takes on your setup.
| Reporter | ||
Comment 12•14 years ago
|
||
>JS is run-to-completion; no new event delivery while your code is running.
>That's expected.
I meant that "tick" events are not present in between 22ms mouse move events.
>... I'm using a C++ profiler; ...
I am not equipped for that and probably I will not be in short term.
Your profiler log and your comments about typed arrays are very useful. I will try fix it.
Comment 13•14 years ago
|
||
> I meant that "tick" events are not present in between 22ms mouse move events.
Ah, interesting. I believe I can reproduce this, or at least I can get multiple mouse moves in a row without a refresh tick in between if I move my mouse fast enough. I also get several refresh ticks in a row for some reason with no mouse events in between. That part is a bit odd, because I thought we tried to avoid that....
I'm going to attach a testcase that can be used for testing this. Olli, cjones, any idea what's going on there with the event delivery?
Comment 14•14 years ago
|
||
Comment 15•14 years ago
|
||
Hmm. If I turn off the delay line stuff, the behavior on my testcase gets a bit better, though I still get two refresh ticks between mouse moves pretty consistently...
We really need to get someone to fix this timer crud. :(
It looks like this page is using a custom mouse cursor. How do things change if you disable that?
Comment 17•14 years ago
|
||
(In reply to Boris Zbarsky (:bz) from comment #13)
> Ah, interesting. I believe I can reproduce this, or at least I can get
> multiple mouse moves in a row without a refresh tick in between if I move my
> mouse fast enough.
Don't we try to process OS events pretty aggressively, and only after that gecko events.
I assume animationFrame is gecko event.
I don't know what to expect from the testcase. I get
tick{0,*} (movestart moveend){0,*} tick{0,*} (movestart moveend){0,*} ...
Comment 18•14 years ago
|
||
> I assume animationFrame is gecko event.
Yes.
> I don't know what to expect from the testcase.
What I get in Chrome is pretty consistently:
{movestart moveend tick}
repeated over and over. Again, nixing the delay line seems to help things a bit here, so maybe that's all that's going on...
| Reporter | ||
Comment 19•14 years ago
|
||
(In reply to Chris Jones [:cjones] [:warhammer] from comment #16)
> It looks like this page is using a custom mouse cursor. How do things
> change if you disable that?
I have tried and it has no effect on events. There is some speed up when custom cursor does not have to be rendered/erased. Reason why I render custom cursor is that system cursor always reacts faster than application and therefore it feels unpleasant for user.
Comment 20•14 years ago
|
||
(In reply to Olli Pettay [:smaug] from comment #17)
> I don't know what to expect from the testcase. I get
> tick{0,*} (movestart moveend){0,*} tick{0,*} (movestart moveend){0,*} ...
Actually, it seems to be very difficult to get (movestart moveend) (movestart moveend) without
tick between
| Reporter | ||
Comment 21•14 years ago
|
||
>If you have a version of this page that logs the event durations, could I take a >look at that?
http://photoraster.com/bugzilla001/index2.html
>Also, if it's possible to have your handler run all the JS it runs but not make >any GL calls ...
It would be very hard. Too many things is interdependent.
Comment 22•14 years ago
|
||
> Actually, it seems to be very difficult to get (movestart moveend) (movestart moveend)
> without tick between
It's trivial for me on my Mac laptop...
David, thanks. I'll take a look at that page!
Comment 23•14 years ago
|
||
OK, I'm seeing 30-40ms mousemove times (and 10ms ones in Chrome). So we should really focus on why those mousemoves are being so expensive....
Comment 24•14 years ago
|
||
What do you mean with 30-30ms mousemove times? Does the event listener take that much or
is it dispatching mousemove from widget level + event listener handling ?
Comment 25•14 years ago
|
||
The event listener is taking that much. Sorry that wasn't clear. The relevant info is comment 11.
| Reporter | ||
Comment 26•14 years ago
|
||
(In reply to Boris Zbarsky (:bz) from comment #23)
I have updated application at my site. New version has redesigned processing of events. During mouse events it only store event state to the buffer. Events stored in buffer are processed together during "tick" event. All processing and UI scanning is done only in "tick" event. This is much cleaner design. It also reduces differences in processing events in different browsers. I have also eliminated some redundant redraws in application. As result application improved performance in FF.
>11% uniformMatrix_x_fv() calls (about half typed array creation and half
> UniformMatrix4fv_array); I assume you could speed this up by actually
> passing in typed arrays, right?
Are you suggesting that this call:
gl.uniformMatrix4fv(_shader._data, false, new Float32Array([ .... ]));
is faster then this one:
gl.uniformMatrix4fv(_shader._data, false, [ .... ]);
Content of array is different for each call.
If you need old version of application, then you can find it at this address:
http://photoraster.com/bugzilla002/index2.html
Comment 27•14 years ago
|
||
(In reply to Boris Zbarsky (:bz) from comment #11)
> 23% drawElements() calls on the rendering context; this is largely
> glDrawElements_ACC_Exec and glDrawElements_Exec.
Under drawElements, is a significant/large part of the time spent in symbols that match 'WebGL' (e.g. WebGLBuffer::FindMaxElementInSubArray) ?
Comment 28•14 years ago
|
||
> Are you suggesting that this call:
> gl.uniformMatrix4fv(_shader._data, false, new Float32Array([ .... ]));
> is faster then this one:
> gl.uniformMatrix4fv(_shader._data, false, [ .... ]);
It's worth testing; internally we end up creating a Float32Array out of the JS array. If you can create a single Float32Array and just reuse it, filling with different numbers, that may be the fastest approach.
> Under drawElements, is a significant/large part of the time spent in symbols that match
> 'WebGL'
I don't remember (and don't have the profile in front of me anymore), but almost all the time ends up under the two glDrawElements*Exec functions.
Updated•13 years ago
|
Whiteboard: webgl-perf
Comment 29•7 years ago
|
||
Let me know if this is still a problem!
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → INCOMPLETE
You need to log in
before you can comment on or make changes to this bug.
Description
•