-
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
player: coalesce option updates and drop redundant ones #15828
Conversation
For some reason, mp_option_change_callback had weird special logic on init to start the ipc client. This makes no sense. It should just be started in mp_initialize like all the other clients.
036d6fe
to
0729afe
Compare
Download the artifacts for this pull request: |
0729afe
to
f4af141
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle it make sense. I didn't think hard about corner cases that it might produce, but the change is not invasive, so we can monitor the impact.
And overall this is nice optimization if for whatever reason some option is spammed to be updated.
The big option callback in player/command will trigger on every single update. This is not so great when several heavy option changes are called in rapid succession and operations are pointlessly repeated. Try to copy the approach that input commands do and run the actual callbacks during the playloop. This is not really a smart or sophisticated mechanism. It also only works for the main option cache. In theory, other option caches like vo_opts could get spammed too and this makes no attempt on those. But regardless, this is probably good enough for us. mp_option_change_callback now tries to group together any new callbacks with existing unprocessed ones and drop redundant ones whenever something new arrives.
f4af141
to
8b54deb
Compare
Should we document it? Not sure where. But option callback won't be immediate now. So I wonder if it is not a problem. Say someone do |
I did a few crude tests fully expecting it to break something but it didn't. Probably still needs some more testing to see if it does something unexpected. |
One issue is that many of the functions called in the option change callback do nothing when the option value is not changed. Example: Line 247 in 5809d4d
Which means if the option is changed to another value before changing it back to the original value, it would do nothing, instead of reloading the script. There are many other examples of this value change detection: Line 161 in 5809d4d
I don't know how this will affect usage in practice, but there are many things handled inside this callback so the potential change in behavior is high. |
Yes, this is pretty clear that some sequence of events may not occur. This is what this change suppose to fix. Like we can read in PR description.
will no longer rapidly change hwdec, possibly reinitializing whole VO. Same with your pause example. The change has impact for sure, but like I said previously I'm not sure what corner cases it can trigger in real usage. I mean it is hard to imagine someone depends on behavior of executing commands in real time manner. |
Internally, the option values do still change with this. So for a command that is like As for clients, we already actually coalesce notification for property/option changes. If something changes the value of a property a bunch of times in a row, the observer will only see the latest change. This PR does not change the behavior there. So I think the potential impact is probably pretty low but again hard to predict since we have so many options that interact in so many ways. |
This breaks
|
Well that was fast. Neither of those options even run callbacks so I'm not sure how it's even possible. Investigating... Edit: Turned out to be a small miss. |
PR mpv-player#15457 has not been rebased after merge of mpv-player#15828 resulting in type mismatch. Fixes: f57c0af
The refactoring in bbac628 missed that the initial update handler didn't immediately run all the triggered callbacks but would instead delay it until the next playloops. This subtly breaks things of course like hooks, force window handling, etc. Ensure that we immediately run all the callbacks like before on startup. Fixes bbac628 Fixes mpv-player#15828 (comment)
The refactoring in bbac628 missed that the initial update handler didn't immediately run all the triggered callbacks but would instead delay it until the next playloop. This subtly breaks things of course like hooks, force window handling, etc. Ensure that we immediately run all the callbacks like before on startup. Fixes bbac628 Fixes mpv-player#15828 (comment)
The refactoring in bbac628 missed that the initial update handler didn't immediately run all the triggered callbacks but would instead delay it until the next playloop. This subtly breaks things of course like hooks, force window handling, etc. Ensure that we immediately run all the callbacks like before on startup. Fixes bbac628 Fixes #15828 (comment)
Could use some more testing for sure, but it seems like the dumb way of just processing these in the playloop does the trick.
Stuff like
input-commands
orhwdec
are good to test since it's obvious if those do repeated executions. e.g. consider these config files.Load them at runtime with
load-config-file
. On master, the first one spams the terminal with garbage because of constant probing. The second one freezes the player and probably will OOM. With this PR, only the last hwdec is processed on the first config file and the second one just quits the player since you're giving loadfile garbage.Bonus:
Results in this on master:
With this PR: