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

Add a grace period between detecting a change and triggering generation in live preview #1412

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

modelflat
Copy link

As per discussion in #1248 this PR adds logic to delay the live preview generation upon change (without the extensions mentioned in this comment).

…on in live preview

* This will prevent some of the "useless" generations, e.g. from the very start of
  the brush stroke
* Period is configurable in settings; setting the default to 0 to
  preserve the existing behaviour

This at least partially addresses/follows the discussions in Acly#628 and Acly#1248
@Acly
Copy link
Owner

Acly commented Nov 19, 2024

This is more of an absolute timer though, which doesn't refresh if there are more changes after the first change, right?
I understood it as a (fairly short) period where there are no more changes instead.

It might be easier to implement that by tracking the timestamp of the last change. Since it's already a loop with a sleep it could be quite simple, something like

if self._last_input != new_input:
    current_time = time.monotonic()
    if current_time - self._last_change < grace_period:
        await self._model._generate_live(new_input)
        self._last_input = new_input
    self._last_change = time.monotonic()

I think this would make it unnecessary to pass _last_input to _generate_live and call _prepare there since that part is already handled. The just_got_here would also not be needed, since the _last_change timestamp would naturally be quite old in this case.

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.

2 participants