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

Queue binding operations without checking thread #5510

Merged
merged 2 commits into from
Feb 6, 2025

Conversation

Jacalz
Copy link
Member

@Jacalz Jacalz commented Feb 6, 2025

Description:

Once #5509 is merged, running binding callbacks from main no longer print a warning so we cna avoid checking the thread. The result is much faster performance.

I also fixed a bug where we were scheduling s.DataChanged() onto main, which in itself then runs a trigger() which schedules the work onto main. That was unnecessary overhead.

Checklist:

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

Once fyne-io#5509 is merged, running binding callbacks from main no longer print a warning so we cna avoid checking the thread. The result is much faster performance.

I also fixed a bug where we ere scheduling s.DataChanged() onto main, which then runs a trigger() which schedules other work onto main. That was unnecessary overhead.
@coveralls
Copy link

coveralls commented Feb 6, 2025

Coverage Status

coverage: 62.585% (-0.001%) from 62.586%
when pulling da0856d on Jacalz:binding-func-scheduling
into 3f7f987 on fyne-io:develop.

data/binding/convert.go Outdated Show resolved Hide resolved
dweymouth
dweymouth previously approved these changes Feb 6, 2025
Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

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

I /think/ that DataChanged should be called on main as it is part of the public API and could be called back into user facing code.

I also fixed a bug where we were scheduling s.DataChanged() onto main, which in itself then runs a trigger() which schedules the work onto main. That was unnecessary overhead.

There may be a bug in here, but I think the right solution is slightly different.

@Jacalz
Copy link
Member Author

Jacalz commented Feb 6, 2025

There may be a bug in here, but I think the right solution is slightly different.

I'm not sure I agree. We said that data bindings should be thread safe, did we not? Also, the old code was inherently wrong as it scheduled a call onto main which then just scheduled a call onto main. I don't see this being any worse than it already was. There is no functional change there in this PR, it just avoids bouncing once on main before again going to main and running the actual stuff there.

@Jacalz
Copy link
Member Author

Jacalz commented Feb 6, 2025

DataChanged() for the conversion types literally only calls trigger() which itself schedules the data listener updates onto main. We don't need to call DataChanged() on ourselves from main.

@Jacalz
Copy link
Member Author

Jacalz commented Feb 6, 2025

Ah, I kind of see what you mean. We would match other binding types better by just calling .trigger() in those instances.

@andydotxyz
Copy link
Member

DataChanged() for the conversion types literally only calls trigger() which itself schedules the data listener updates onto main. We don't need to call DataChanged() on ourselves from main.

The core of this is that DataChanged is in the listener API - anyone that called AddListener would expect the Fyne callback to be on the correct thread.

I think this is now correct.

Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

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

Thanks, I think that's the threading sorted now.

@Jacalz
Copy link
Member Author

Jacalz commented Feb 6, 2025

I think this is now correct.

Thanks. Yeah, I agree and your explanation matches my understanding as well now. Anyone actually calling DataChanged on those types would still get a double bounce on main unfortunately. Might be a problem for a future PR though

@Jacalz Jacalz merged commit 71764a2 into fyne-io:develop Feb 6, 2025
11 checks passed
@Jacalz Jacalz deleted the binding-func-scheduling branch February 6, 2025 21:58
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.

4 participants