Skip to content

Add a note about polled events and the later package #836

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

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

Conversation

DavisVaughan
Copy link
Contributor

Documenting that switching from 200ms to 50ms helped with posit-dev/positron#7235

We did the switch in this commit 452b84f

@lionel-
Copy link
Contributor

lionel- commented Jun 12, 2025

hmm if I set it to 1250ms or even disable polled events entirely I still get a short time.

@DavisVaughan
Copy link
Contributor Author

DavisVaughan commented Jun 12, 2025

@lionel- I think I know why. Winston added later::run_now() to his original example, which messes things up if you're trying to rely on the R_InputHandlers being flushed. Try this

# Put these in a block to ensure they're run without delay in between.
{
  later::later(\() { finish <<- Sys.time(); cat("Finished!")}, 0)
  start <- Sys.time()
}

# Wait for a moment after running block above.
# Then run:
finish - start

This respects the 1250ms delay, and gets faster with the 50ms delay.

(As he noted, we don't see the cat("Finished!") output in this case)

@DavisVaughan
Copy link
Contributor Author

It's definitely tied to this delay, we run the input handlers here

pub fn run_activity_handlers() {

Which is called from process_idle_events()

fn process_idle_events() {
// Process regular R events. We're normally running with polled
// events disabled so that won't run here. We also run with
// interrupts disabled, so on Windows those won't get run here
// either (i.e. if `UserBreak` is set), but it will reset `UserBreak`
// so we need to ensure we handle interrupts right before calling
// this.
unsafe { R_ProcessEvents() };
crate::sys::interface::run_activity_handlers();

Which is what we do on each 50ms tick

Self::process_idle_events();

@@ -825,7 +825,8 @@ impl RMain {

// Process R's polled events regularly while waiting for console input.
// We used to poll every 200ms but that lead to visible delays for the
// processing of plot events.
// processing of plot events, it also slowed down callbacks from the later
// package. 50ms seems to be more in line with RStudio (posit-dev/positron#7235).
Copy link
Contributor

Choose a reason for hiding this comment

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

Also add link to #791?

Copy link
Contributor

Choose a reason for hiding this comment

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

No need, this is unrelated to the {later} issue.

@DavisVaughan Should we use an even smaller timeout?

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