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
Minimize sequence unwrapping and instantiating #206
Comments
Ah, OK. Then I would suggest we change then() back to the way it was and
replace + with +=. Otherwise, it would be poor practice to ever use either
of these if you don't like your game stuttering.
…On Wed, Aug 21, 2019 at 3:07 AM MJ ***@***.***> wrote:
I believe that's how it was implemented at first, but we eventually
decided against it, since + operator in Kotlin should not mutate either
of the operands. See #172 <#172> #174
<#174>
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#206?email_source=notifications&email_token=AAOB7O3JDJXDGBHD5MOG5HLQFTSUNA5CNFSM4IN7KKVKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4YVOJY#issuecomment-523327271>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAOB7OYYTAMGU6UKKIPPXJDQFTSUNANCNFSM4IN7KKVA>
.
|
Depends on the amount of actions that you use and the target device. Unless you're spawning thousands of sequence actions, creating a few extra short-lived objects here and there should not be an issue. Modern JVMs are rather powerful. On desktop this is unlikely to be a problem. On mobile - well, you can deal with it if it becomes an issue. Also, having a non-mutating variant is useful when you don't want to modify the sequence actions. Even the garbage collection aside, there could be use cases for that alone. That being said, I can see why providing a mutable variant would be beneficial. Would you like to submit a PR with |
I see what you mean about performance. A few years ago, generating a few dozen objects worth of garbage would get you a noticeable GC stutter on a mid-range phone. I've used Actions as easy tween managers before, and in those projects I'd be creating many sequences. Of course, phone performance has advanced very quickly so maybe it's no longer an issue unless the amount of actions created is extreme. I agree it would be nice to have options, and it makes sense for Maybe for ParallelAction a nice infix function name would be I'll play around with it a bit the next few days. We have to be careful with functions on ParallelAction since SequenceAction is weirdly extended from it. |
You can see Git history to check how it was implemented before the non-mutating variants were introduced. I think the parallel and sequence actions API should be consistent. We could stick with operators being non-mutating, and their more verbose variants being mutating. Otherwise there is no obvious distinction or reason why By the way, I really like the name |
I found a serious bug while experimenting with this. I'll include the fix in my PR (should be today or tomorrow). Since SequenceAction is a ParallelAction,
|
I'd expect these to have a common superclass, but not extend one another. Thanks for the fix, I'll review the PR this week. |
I'm also not sure if we should unwrap actions in the first place. It seems like it would be a really rare occurrence in practice with hardly any benefits, and might lead to some weird bugs (e.g. someone keeps a reference to a sub-sequence to track it for whatever reason, and it ends up being cleared and freed immediately). What do you think, @cypherdare? |
Yeah, I had thought of that. In my opinion, non-mutating should just wrap them both every time so it's not causing the original objects to be useless. Also, they'll get picked up by their pools when they are run. Let me know what you think and I can update it. Do we care that there's a I'm thinking I'm going to PR libGDX to break up the bug-prone hierarchy. |
Agreed, I'd appreciate if you update the PR.
When you override
Good idea. |
Thank you for your contribution, @cypherdare. Snapshot release with your changes will be available shortly. I might also release |
Sure, and thank you for the library! |
I started to do a PR for this but it causes an existing test to fail, so I think it needs discussion.
IMO,
SequenceAction.then
should not unwrap its children if it can be avoided. Consider:The first operation creates a SequenceAction. The second operation immediately unwraps that sequence and creates a new sequence to put the same two original actions in. Then the third operation unwraps that sequence to transfer three actions.
So a simple sequence of 4 actions results in 3 SequenceActions instantiated and has transferred actions 5 times.
If we do this:
Only one SequenceAction is instantiated and no actions have to be unwrapped, no matter how long the chain of actions is. However, this fails the test
should not mutate multiple actions with then
, which raises the question of, Why shouldn't it mutate if it can avoid all the extra memory churn? Why is it better to throw away a SequenceAction than to mutate it?Incidentally, I think
addUnwrapped
should also free the SequenceActions that it throws away, since they are no longer useful and their reference is likely to be lost. Like this:The text was updated successfully, but these errors were encountered: