nwjs / nw.js

Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
https://nwjs.io
MIT License
40.34k stars 3.88k forks source link

Win7-8 Intermittent Mouse Event Lag (Simple Test Case Included) #1169

Closed gurok closed 8 years ago

gurok commented 11 years ago

Hello,

I've noticed Node Webkit behaving strangely when it comes to mouse events on my main Windows 8 machine. An object set to move on mousemove will sometimes stop and lag for a good 2-3s before the object catches up with the mouse. In Chrome, the same code behaves normally. I have tried using the profiling tools to determine the cause of the issue, but they just show a huge gap between frames and no processing occurring in the gap. If I turn on the FPS meter, the frame rate doesn't drop even though it's clearly giving an incorrect value (no frame for 2-3s = 60FPS?).

I've created a test case which demonstrates my problem:

http://goldenflameproductions.com/unrelated/testcase.zip

Strangely, I can "fix" the problem with the following code (that I've commented out of the test case):

setInterval(function() { }, 30);

I have a fair idea of how this is working. If I use 500 for the interval, the maximum lag I'll see is 500ms rather than 2-3s. I'd say it's just making NW check for events more often than it would otherwise.

It might be specific to my machine in some way, just not sure what it is. I know it's at least somewhat OS-specific. I'm running Windows 8 Professional (64-bit). I couldn't replicate it on my 32-bit XP-based netbook. I'm using NW 0.75.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

szwacz commented 11 years ago

I certainly can reproduce the problem on Windows7 nw v.0.7.3.

But I have failed to find any pattern what is going on. Once there are several freezes one after another, and then no freeze for long time.

CPU usage looks ok during freeze, so FPS count could not lie to you. Problem seemed to disappear when I turned on the record heap allocations in devtools (but I didn't try very long while recording, about 2 minutes).

katanacrimson commented 11 years ago

Can you use Resource Monitor to observe what's going on with more aspects of the system, perhaps? Check disk I/O specifically, see if that's your bottleneck.

szwacz commented 11 years ago

Resource Monitor shows no spikes during freeze in CPU or memory usage, disk i/o is not a variable at all.

This problem is really hard to track. When I add one more element to DOM and animate it with css animation, to see if rendering of whole screen is affected the bug stops to appear.

When I was recording timeline in dev tools:

It could be one of three:

  1. Rendering problem (graphic card stuff, not CPU stuff).
  2. Some strange GC quirk.
  3. Lag in processing events (when after freeze occured you stop moving the mouse (not providing any new move event) after some time the DOM object will sync with your mouse position, so events was not lost, just lagged).

I don't have more time and knowledge to dig deeper. Certainly now someone smarter than me have to look at this issue.

gurok commented 11 years ago

Hey szwacz, thanks for confirming that it's not just an issue for me! :D I have taken a screenshot, but I agree with everything you've said. Especially the lag processing the event part. If you don't move the mouse, NW will eventually "catch up". That's definitely how it behaves for me. Yep, and adding an animation or even just a setInterval will fix the problem.

Here's a Resource Monitor session where I had multiple (maybe a dozen) hangs:

resource_monitor_2

Here's a screenshot with just Resource Monitor and the Frames Timeline view running on my local machine. I get a few spikes in resource usage, but they're pretty minimal. Note: I only get these while the Frames Timeline is recording, so I think it might have something to do with that. You can see the CPU drop significantly at the point of the hang (Frames Timeline isn't recording anything).

resource_monitor

I've included the Frames Timeline stuff because I think it best illustrates the gap I'm seeing in event/frame processing by NW.

YurySolovyov commented 11 years ago

I can cofirm that too, thought just my issue. Win 8 x64 Ent.

darsain commented 10 years ago

Happening for me as well on Win 7 x64 with v0.7.5 as well as v0.8.0-rc1, but it is way more extreme. Here is the timeline:

Timeline

The gaps between repaints are freezes, and as you can see it is happening all the time. The app is virtually unusable. Quite often the app stays interactive for less than a second before returning into 5-6 seconds long freeze.

This is the page I'm using to test this: http://hastebin.com/dikelabiyi.html Just a simple html page without anything going on. The freezing is obvious when you move cursor over the boxes and they are not being repainted.

No heavy processing is going on, CPU and GPU are mostly idle, RAM is OK too. In fact, watching it in the Process Explorer, the CPU consumption of nw.exe processes is going down during the freezes.

Adding an empty loop:

(function render() {
    requestAnimationFrame(render);
}());

as suggested above seems to fix the issue.

rogerwang commented 10 years ago

@gurok I'm not able to download your case. Could you please check?

rogerwang commented 10 years ago

@Darsain When I'm trying to open your link in browser, it is redirected to http://hastebin.com/ . Is this expected?

gurok commented 10 years ago

Sorry. My web server volume crashed. I've uploaded it to a free file host: http://stashbox.org/1295197/testcase.zip

darsain commented 10 years ago

@rogerwang didn't knew hastebin was deleting stuff after some time :/ Here is a gist: https://gist.github.com/Darsain/7511199 Or jsbin: http://jsbin.com/IvibucER/1/edit

The problem is, I have no idea what is causing it. It isn't consistent (sometimes it is more responsive, sometimes less), and seems to affect only some machines. Tested it on 2 different Win 7 PCs and one is having these issue, while the other is completely smooth. The speed of the machine is also irrelevant, as the smooth one was Eee PC notebook.

I've also tried restarting the affected machine and turning everything unnecessary off. All BG apps, and processes that were not needed. Had no effect.

roberthartung commented 10 years ago

Hey everyone I am seeing this issue with an animation I made with window.requestAnimationFrame. Is there already some fixing going on - has the bug been identified?

Regards, Robert

a-type commented 10 years ago

This bug is causing major issues for my project. Has anyone identified its cause? Could it be a GC issue? I am using node-webkit in conjunction with ThreeJS to create a simple desktop model viewer, but the app is all but unusable due to constant multiple-second hangups, even on very simple scenes.

rogerwang commented 8 years ago

This should be working with latest 0.13 version now.