dionyziz / Automata

An editor for deterministic finite automata
http://automata.discrete.gr
51 stars 12 forks source link

Fixed high CPU load due to constant rendering in the loop. #45

Closed DmitryMyadzelets closed 9 years ago

DmitryMyadzelets commented 9 years ago

This PR fixes issue #25. The discussion of this issue points out that rendering has to occur in the three cases. It seems true, but just calling renderer.render() during dragging states by mouse reveals a worse performance than it was initially. It happens when a rendering rate, which depends on number of mousemove events, is higher then a possible animation frame rate. The solution is to use requestAnimationFrame and invoke it only when there is a need and the previous request is processed ('rendering_requested' attribute of the renderer). And that has been done.

During resize of the window we can call renderer.render() directly for the immediate redraw. It looks better then calling renderer.requestRender().

Below is the CPU load on my PC before this patch: before

and after: after

On the last picture the high CPU load in the end occurs while dragging a state.

DmitryMyadzelets commented 9 years ago

I've just found that running the Runner by on-screen arrows doesn't result in rendering of the automaton. Keyboard works, though.

dionyziz commented 9 years ago

Looks good, looking forward to merging this. Please address the comments above and let's continue :)

dionyziz commented 9 years ago

Thanks for your work :)