Use RequestAnimationFrame instead of Timers #54

Open
TheSavior opened this Issue Mar 7, 2014 · 4 comments

Projects

None yet

2 participants

@TheSavior
Contributor

There have been some comments about things not running as fast as advertised ( #49 #51), and skipping words ( #39 #41). I believe all of these issues are because we are using Timers to change the words. Timers work great for long running things that don't need much precision, but work terribly for running things really quickly.

In Chrome, with Timers, it can only run at 10fps, which means that it doesn't matter how fast you set it, it can't beat 10fps, so some frames will either be dropped, or it won't go as fast as we would like.

If we switch to using RequestAnimationFrame, we can guarantee the browser will run our code at 60fps, so we should be able to go significantly faster and smoother. This would also allow us to clean up the code for delaying on long words and being able to change the speed in the middle easily.

@Miserlou
Owner
Miserlou commented Mar 7, 2014

That sounds like it makes way more sense..

On Fri, Mar 7, 2014 at 3:22 PM, Eli White notifications@github.com wrote:

There have been some comments about things not running as fast as
advertised ( #49 #49 #51#51),
and skipping words ( #39#39
#41 #41). I believe all of
these issues are because we are using Timers to change the words. Timers
work great for long running things that don't need much precision, but work
terribly for running things really quickly.

In Chrome, with Timers, it can only run at 10fps, which means that it
doesn't matter how fast you set it, it can't beat 10fps, so some frames
will either be dropped, or it won't go as fast as we would like.

If we switch to using RequestAnimationFrame, we can guarantee the browser
will run our code at 60fps, so we should be able to go significantly faster
and smoother. This would also allow us to clean up the code for delaying on
long words and being able to change the speed in the middle easily.

Reply to this email directly or view it on GitHubhttps://github.com/Miserlou/OpenSpritz/issues/54
.

@TheSavior
Contributor

Apparently my math was wrong and this probably wouldn't speed things up. It was running at 10fps because 600WPM / 60 seconds = 10 frames per second. >_<

RequestAnimationFrame is still the way to go, especially for code cleanliness, but it might not fix the skipping words issue. It's also more likely to keep the code running as fast as we want it, and not to be hit by the occasional time delay in the timers (does this happen?)

Before a change like this is made though, I'd really like to see the whole codebase refactored into something more like #33 so that people can actually follow how it will work down the road.

@Miserlou
Owner
Miserlou commented Mar 7, 2014

Agreed.

However, however I think if we're going to be doing a major refactor, I'd
like to get JSONP worked into that as well.

On Fri, Mar 7, 2014 at 3:30 PM, Eli White notifications@github.com wrote:

Apparently my math was wrong and this probably wouldn't speed things up.
It was running at 10fps because 600WPM / 60 seconds = 10 frames per second.

RequestAnimationFrame is still the way to go, especially for code
cleanliness, but it might not fix the skipping words issue. It's also more
likely to keep the code running as fast as we want it, and not to be hit by
the occasional time delay in the timers (does this happen?)

Before a change like this is made though, I'd really like to see the whole
codebase refactored into something more like #33https://github.com/Miserlou/OpenSpritz/pull/33so that people can actually follow how it will work down the road.

Reply to this email directly or view it on GitHubhttps://github.com/Miserlou/OpenSpritz/issues/54#issuecomment-37079457
.

@Miserlou
Owner
Miserlou commented Mar 7, 2014

Eli - do you have a preferred email address? I sent a note to the one on
your resume.

On Fri, Mar 7, 2014 at 3:32 PM, Rich Jones rich@anomos.info wrote:

Agreed.

However, however I think if we're going to be doing a major refactor, I'd
like to get JSONP worked into that as well.

On Fri, Mar 7, 2014 at 3:30 PM, Eli White notifications@github.comwrote:

Apparently my math was wrong and this probably wouldn't speed things up.
It was running at 10fps because 600WPM / 60 seconds = 10 frames per second.

RequestAnimationFrame is still the way to go, especially for code
cleanliness, but it might not fix the skipping words issue. It's also more
likely to keep the code running as fast as we want it, and not to be hit by
the occasional time delay in the timers (does this happen?)

Before a change like this is made though, I'd really like to see the
whole codebase refactored into something more like #33https://github.com/Miserlou/OpenSpritz/pull/33so that people can actually follow how it will work down the road.

Reply to this email directly or view it on GitHubhttps://github.com/Miserlou/OpenSpritz/issues/54#issuecomment-37079457
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment