-
Notifications
You must be signed in to change notification settings - Fork 3k
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
feat(async): adds AsyncScheduler and updates appropriate operators. #1395
Conversation
@trxcllnt why do we not have a separate schedule method like schedulePeriodic for when setInterval is necessary? Let's chat about this before merging because I want to bring in long running scheduling which avoids recursive scheduling which is what I'm retrofitting into v4... |
@mattpodwysocki well, mostly because early on we knew we wanted a smaller scheduling API and that recursive scheduling could accomplish all scheduling variants. replacing the state and reusing the scheduled action is effectively tail-call optimization. |
@mattpodwysocki I also ran some rudimentary tests in jsperf that show using |
I suggested the same thing in Slack.
... except it's weird and confusing to look at in the code. |
I'm really against breaking this API, @trxcllnt. It would be a breaking change. Before It seems like what we really want is The other thing is the need to schedule things on a repeating basis is really an edge case for schedulers. Most of the time schedulers are scheduling one thing and they're done. It is interesting that setInterval is faster in Chrome than setTimeout. But given that this is something that's happening on a delay anyhow, I'm not sure the perf win is going to be noticeable enough in any meaningful way to justify the breaking change. |
even a ... but I like |
That's not true. The behavior of |
In the beginning, you and I set a goal of simplifying and optimizing the schedulers. We acknowledged that recursive scheduling was the most general case that would enable all the existing scheduling strategies, while being simple enough to fully optimize. What's the point of making the API more complex than it has to be?
Does anybody really look at the scheduler internals much? Optimization ain't always pretty. |
@trxcllnt Thank you for your PR, but I do think that the reason it is breaking in Angular is due to the recursive scheduling. I am not asking any of you to fix it on your end, but if you could that would be great. |
@Guardiannw recursive in this context doesn't refer to literal recursion, but is a metaphor for the API that allows scheduled actions to reschedule themselves. Past versions of Rx did use recursion, which wasn't TCO, so we've optimized in the latest version. This is not the source of your memory leak. |
@trxcllnt I think I knew that already, but I am pretty sure that zone.js keeps track of that. That zone.js actually monitors a stack trace through what set the timeout and then where it went and then what set it and then where it went and then...... so on and so forth. Thereby creating an infinitely long stack trace full of leaked memory as the interval goes on and on. |
@Guardiannw then it sounds like moving from repeated |
@trxcllnt Yes I think it would. I just think that it would be best not to use |
@trxcllnt Yes, I very much believe that that is what is causing the problem. |
If there were any meaningful difference between canceling This PR fixes multiple outstanding issues (including yours, it sounds like), is faster, doesn't contain any breaking changes, and doesn't increase API surface area. I don't know what more we could ask for in a PR. |
Hey I'm open to hearing from guys much more intelligent than me. |
@Guardiannw feel free to clone this branch and see whether the memory leak is still there or not. |
@trxcllnt I cloned and ran tests on your branch and your PR does indeed fix my other memory leak issue. I had to add the fix #1394 as well in order to be sure no memory leaks exist anymore. After I did both your branch and that fix, things are working like a dream. No memory leaks... @Blesh @mattpodwysocki Please move forward where you all want to, but please somehow incorporate this fix in some way so that we have this bug fixed. Thank you all, |
1aae1b7
to
917f388
Compare
@Blesh @mattpodwysocki as far as I can tell, we have two options here:
I don't care which one we choose, but we've gotta choose one. I chose option 2 on the basis that it was less work, but if someone (not me) wants to take on the work for option 1, be my guest. |
It's not a breaking change. It's adding a new method to the type, and not at all changing the other method. Unless I'm mistaken, what you're proposing is a breaking change. Currently:
After the proposed change:
... either way, in a |
Also, this PR is doing way too much.
... all in one commit, and without much discussion by the community. I'm not trying to be adversarial, @trxcllnt, but I don't think I agree with the PR, and it's even harder for me to agree with it when it's doing so much. |
@Blesh I'm sorry, this PR does not automatically re-execute the action unless it's disposed (added an inline comment showing where the interval is canceled if the action isn't rescheduled). The API change would be a breaking change because it would break actions that reschedule themselves recursively (i.e. remove the ability for a scheduled action to call |
917f388
to
1c96b5c
Compare
Okay... after reviewing this PR and discussing with Paul in Slack, I think what we've got here is fine. I misunderstood the The AsyncScheduler makes total sense, and I think we needed that. I'm dubious on the name, but it's fine for now I think, and "sounds" like it comes after The other changes to default some operators to use the async scheduler seem totally fine. |
Also, I LOVE the fact that @trxcllnt commented the hell out of |
LGTM |
Kudos for the comments! 👏 We should do it more. ;) |
@Blesh sure. do you need me to rebase and resolve merge conflicts? |
@trxcllnt: If you'd be so kind, yes. |
1c96b5c
to
8da54f6
Compare
@Blesh done |
@Blesh could we merge this PR now? |
LGTM |
8da54f6
to
05719b2
Compare
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Adds
Scheduler.async
which will always schedule an action to happen in the future. Fixes #1339. UpdatesFutureAction
to usesetInterval
instead of repeatedsetTimeout
calls as discussed with @mattpodwysocki in #1391.