-
Notifications
You must be signed in to change notification settings - Fork 142
[RAF] Remove FPS limiting to consider other possible features #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ding other features, like passing down a `delta` or how many frames have been painted in a given second, options that could be used while limiting frames or not.
|
Note: rAF is often used for animation. Perfectly fine to animate 12 or 24 FPS ("Into the Spiderverse" was mostly 12 FPS, sometimes 8FPS). I've done testing on smaller things like switches & found 15FPS worked nicely. Lowering FPS saves on power, & can help free up CPU/GPU for other more important tasks. |
|
I get what you're saying, there are probably plenty of other features the raf package could be providing. The createRAF(captureDelta(delta => {...}))If you're interesting in rewriting the API though, we could have a |
|
I would have preferred an options object, as this is dealing mostly with data that we already had in the loop. Makes it also easier to use and see how you get the information. I tried to think how the composable approach would work. I'm having a hard time. It is something like this? createRAF(
targetFPS(timeStamp => {
countFrames(frames => {
captureDelta(delta => {
callback(timeStamp, frames, delta)
})
})
}, 15),
) |
|
Composition can sometimes lead to more boilerplate, but you get things like control, explicitness and replaceability in exchange. It is also more tied to the ideal of this library, of shipping small, composable primitives. let lastTimestamp = 0;
createRAF(
targetFPS((timeStamp) => {
const delta = calcDelta(lastTimestamp, timeStamp);
const frames = calcFPS(delta, 15);
callback(timeStamp, frames, delta);
}, 15)
);This way we are also keeping the interface as close to the browser api as possible. But if there are some improvements to be made then be should explore that. For example how often do you use the delta to calculate values for animation? It sounds like something you should always be doing, but I can image that a lot of people are not using it this way. (I wasn't doing it previously either) So should it be a part of the base createRAF((timestamp, delta) => {
const frames = calcFPS(delta);
callback(timestamp, frames, delta);
});
// or with fps throttling
createRAF(
targetFPS((timestamp, delta) => {
const frames = calcFPS(delta);
callback(timestamp, frames, delta);
}, 15)
); |
|
The delta time is a useful value, for more than animations. This is a great post about considerations if used in animations https://stackoverflow.com/a/46346441 I understand the gains of compostability, I just imagined this to be differently. the callback could have had an Anyway, if you are happy with it, feel free to close this, thanks for your time. |
|
Perhaps this is just a matter of exporting Edit: I misunderstood the original thread. The issue is composability itself being difficult/tricky. Sorry for the confusion haha. Let's just keep in mind that the primitive should balance performance, ease and base functionality. Too much composability makes this cumbersome to use. So striking a balance where the base primitive is packaged with a few extras (maybe delta) and then compose targetFPS and countframes on top of that. |
|
I want to clarify something. This pull request is about not introducing more breaking changes till consensus could be reached about how to handle or implement the extra features. The state of it, is already a breaking change, what I am trying to do here is to not break more than needed, as this may have not been adopted yet (been merged yesterday). The thing is how we move forwards, considering the additional expected features. As I said before, there are not many features that can be given by this. Roughly speaking, we may want to do the following:
I'm not convinced that there's a need to provide compostability to deal with this, I think an options object would suffice. But that's just me, obviously. I favour performance on this case over anything else, this is probably one of the hottest function of the whole library. I will never use it if this calls 1k functions every second. Maybe @trusktr was right, and this pull request should be merged, so to each their own about how to deal with the features. |
|
Imma close it and if there's anything to contribute I will open a new one!, Thanks! |
Off the top of my head, I could think that what almost any fancy requestAnimationFrame need is:
targetFPS, run at most N FPSdeltavalue, how much time elapsed since the last runWhat most people need is none of the above, but that's not the point. Others would find these values to be passed down useful.
I'm proposing to start over, because this is a fresh and breaking change, and having people to use it, will make them to then have to change the way it's used in the future, and nobody likes that. The proposal made in #78 considered the above, but what got merged somehow is not considering it.
The
targetFPScallback that got implemented was very clever, but how do we add additional features that won't get repeated around and won't require changing signatures.