Skip to content
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

Make start animations idempotent and improve runner performance #4451

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

dweymouth
Copy link
Contributor

Description:

Fixes #(issue)

Checklist:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

Where applicable:

  • Public APIs match existing style and have Since: line.
  • Any breaking changes have a deprecation path or have been discussed.
  • Check for binary size increases when importing new modules.

@dweymouth dweymouth changed the base branch from master to develop December 10, 2023 22:38
@dweymouth
Copy link
Contributor Author

Hmm, all the tests seem to be timing out. Deadlock? Maybe some unit test assumption was broken because the animations in fyne_demo work fine.

@andydotxyz
Copy link
Member

Hmm, all the tests seem to be timing out. Deadlock? Maybe some unit test assumption was broken because the animations in fyne_demo work fine.

Yes it could be. There are assumptions in the Unit Test regarding threading and timing. Fixing them is a good thing if you can figure out where they are ;). I could try to take a look over the coming days if it would help.

@dweymouth
Copy link
Contributor Author

I could try to take a look over the coming days if it would help.

Yes, I think that would be helpful. I am pretty confident my actual code changes haven't introduced the possibility of deadlock. And I gave up, at least for now, trying to track down the assumptions in the test that may need updating.

@andydotxyz
Copy link
Member

Confirmed - container package tests time out locally as well (linux and Darwin). Investigating.

@andydotxyz
Copy link
Member

tabs.go:441 calls r.positionAnimation.Stop() but the animation is already locked so it cannot obtain.

@andydotxyz
Copy link
Member

Aha, animation.Start() was holding the mutex so calling Stop from within the callback would lock.

I updated it it to this and that seemed to work. I hope this helps:

// Start registers the animation with the application run-loop and starts its execution.
func (a *Animation) Start() {
	a.mutex.Lock()
	if a.state == AnimationStateRunning {
		return
	}
	a.state = AnimationStateRunning
	a.mutex.Unlock()

	d := CurrentApp().Driver().(interface{ StartAnimationInternal(*Animation) })
	d.StartAnimationInternal(a)
}

animation.go Outdated
//
// Since: 2.5
func (a *Animation) State() AnimationState {
return a.state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not use the mutex?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to atomic so we're good here

@Jacalz
Copy link
Member

Jacalz commented Jan 9, 2024

With the change proposed above, it seems like it would be a good fit to use sync/atomic (maybe Int32, or Uint32). I suppose it would be quite clean to do a .Swap() to running state and return if the old state was running. This should use a single atomic operation, I think:

old := a.state.Swap(AnimationStateRunning)
if old == AnimationStateRunning {
    return
}

@dweymouth dweymouth marked this pull request as ready for review January 10, 2024 00:40
@dweymouth dweymouth added this to the "Elgin" release, late 2023 milestone Jan 10, 2024
@coveralls
Copy link

Coverage Status

coverage: 64.602% (-0.07%) from 64.674%
when pulling e47e3b2 on dweymouth:animation-fix
into 8d62571 on fyne-io:develop.

@dweymouth
Copy link
Contributor Author

OK I think there is still a possible timing issue where an animation could end up running twice if it is stopped and then immediately started again. I wonder if it's possible to move the runner to the public animation package but make it non-exported? It's hard to get communication right between the animation instance and the runner.

@dweymouth dweymouth marked this pull request as draft January 11, 2024 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants