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

Fix visualizations sometimes not opening with space bar. #5624

Conversation

MichaelMauderer
Copy link
Contributor

@MichaelMauderer MichaelMauderer commented Feb 10, 2023

Pull Request Description

Visualizations closing right after opening was caused by the GUI being unresponsive during loading of some visualizations. This caused the timer for measuring the time between space bar press and space bar release to be inflated. The delayed events triggered the "visualization preview mode”, thus closing the visualization has it seemed that the space bar was held down, even though the events just arrived with some delay.

The problem is mitigated by considering the number of frames that have passed between the space and down and the space bar up event, instead of just the wall clock time. If the number of frames is too low, this indicates that frames were dropped to the time is inflated.

Fixes #5223

Checklist

Please include the following checklist in your PR:

  • The documentation has been updated if necessary.
  • All code conforms to the
    Scala,
    Java,
    and
    Rust
    style guides.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed: Enso GUI was tested when built using BOTH
      ./run ide build and ./run ide watch.

…tion opening do not erroneously close the visualisation as if it was opened as preview.
@MichaelMauderer MichaelMauderer self-assigned this Feb 10, 2023
@MichaelMauderer MichaelMauderer marked this pull request as ready for review February 10, 2023 15:33
@MichaelMauderer MichaelMauderer changed the title Fix visualisation sometimes no opening with space bar. Fix visualization sometimes not opening with space bar. Feb 10, 2023
@MichaelMauderer MichaelMauderer changed the title Fix visualization sometimes not opening with space bar. Fix visualizations sometimes not opening with space bar. Feb 10, 2023
let frames: Counter = default();
let frames_handle = Rc::clone(&frames);
let closure_handle = Rc::new(RefCell::new(None));
let closure_handle_internal = Rc::clone(&closure_handle);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a memory leak here? The closure strongly-references the closure handle, which owns the closure.

type Counter = Rc<std::cell::Cell<i32>>;

#[derive(Debug)]
/// A counter that counts frames thr frames that have passed since its initialization.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo

Copy link
Contributor

@farmaazon farmaazon left a comment

Choose a reason for hiding this comment

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

Please address the leak issue by @kazcw

Comment on lines 97 to 99
/// Number of frames we expect to pass during the
/// `VIZ_PREVIEW_MODE_TOGGLE_TIME_MS` interval. Assumes 60fps.
const VIZ_PREVIEW_MODE_TOGGLE_FRAMES: i32 = (VIZ_PREVIEW_MODE_TOGGLE_TIME_MS / 16.0) as i32;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we assume 60 FPS I would rather put here 1000.0/60.0. Or make assumed FPS another constant

@MichaelMauderer MichaelMauderer added CI: Ready to merge This PR is eligible for automatic merge CI: No changelog needed Do not require a changelog entry for this PR. labels Feb 13, 2023
Copy link
Member

@wdanilo wdanilo left a comment

Choose a reason for hiding this comment

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

I need a better explanation of why this PR works and what was the cause that visualizations were disappearing. The code is probably fine, but it should explain itself for future readers

@@ -94,6 +94,10 @@ pub mod prelude {

const SNAP_DISTANCE_THRESHOLD: f32 = 10.0;
const VIZ_PREVIEW_MODE_TOGGLE_TIME_MS: f32 = 300.0;
/// Number of frames we expect to pass during the
/// `VIZ_PREVIEW_MODE_TOGGLE_TIME_MS` interval. Assumes 60fps.
Copy link
Member

Choose a reason for hiding this comment

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

This lacks documentation of what these constants do. Please add docs to previous constant as well. Also, the explanation Number of frames we expect to pass during the... doesn't really explain what it means and what it is used for.

Comment on lines 3462 to 3463
// We also check the number of passed frames to ensure we did not spend too much time in
// dropped frames during the visualisation initialisation.
Copy link
Member

Choose a reason for hiding this comment

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

What does it mean? What is "too much time"? There is no explanation why this code exists and what it really does.

@MichaelMauderer
Copy link
Contributor Author

I need a better explanation of why this PR works and what was the cause that visualizations were disappearing. The code is probably fine, but it should explain itself for future readers

The problem here is, that we are trying to measure the time between the key down and the key up event. If the key up event happens before the VIZ_PREVIEW_MODE_TOGGLE_TIME_MS has passed, we consider it a normal key press that opens the visualization. If the key up event happens after VIZ_PREVIEW_MODE_TOGGLE_TIME_MS has passed, we assume that a "press and hold” action was performed, which would trigger our visualization preview and thus the visualization should be closed when the key is release. But if the opening of the visualization takes a lot of time, specifically, longer than VIZ_PREVIEW_MODE_TOGGLE_TIME_MS, then the key up event will be processed too late, even if the key was already released right after the key down. We can guard against this by not just measuring the time, but checking that enough frames have passed. Since if we take too much time processing things, we get dropped frames.

I'll now update the docs to make this clearer.

@MichaelMauderer MichaelMauderer removed the CI: Ready to merge This PR is eligible for automatic merge label Feb 14, 2023
Copy link
Member

@wdanilo wdanilo left a comment

Choose a reason for hiding this comment

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

Perfect, now it is fully understandable, thanks!

@MichaelMauderer
Copy link
Contributor Author

@kazcw Could you also re-review tour requested changes?

Copy link
Contributor

@vitvakatu vitvakatu left a comment

Choose a reason for hiding this comment

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

QA passed

@MichaelMauderer MichaelMauderer added the CI: Ready to merge This PR is eligible for automatic merge label Feb 17, 2023
@mergify mergify bot merged commit e81d1e3 into develop Feb 17, 2023
@mergify mergify bot deleted the wp/MichaelMauderer/Opening_visualization_with_space_does_not_always_work_#5223 branch February 17, 2023 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Opening visualization with space does not always work.
5 participants