Skip to content

Cancel preparation tasks for editor functionality if the preparation task hasn't been started yet and the document is no longer active #1323

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

Merged
merged 1 commit into from
May 22, 2024

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 21, 2024

When the user opens documents from three targets A, B, and C in quick succession, then we don’t want to schedule preparation of wait until A and B are finished preparing before preparing C.

Instead, we want to

  • Finish for preparation of A to finish if it has already started by the time the file in C is opened. This is done so we always make progress during preparation and don’t get into a scenario where preparation is always cancelled if a user switches between two targets more quickly than it takes to prepare those targets.
  • Not prepare B because it is no longer relevant and we haven’t started any progress here. Essentially, we pretend that the hop to B never happened.

@ahoppen ahoppen requested review from bnbarham and hamishknight May 21, 2024 04:50
@ahoppen ahoppen requested a review from benlangmuir as a code owner May 21, 2024 04:50
@ahoppen ahoppen force-pushed the dont-stack-preparation-for-editor branch from 10df160 to 17e9205 Compare May 21, 2024 16:30
@ahoppen ahoppen changed the title Cancel preparation tasks for editor functionality if the preparation task hasn't been started yet and the document is no longer active 🚥 #1322 Cancel preparation tasks for editor functionality if the preparation task hasn't been started yet and the document is no longer active May 21, 2024
@ahoppen
Copy link
Member Author

ahoppen commented May 21, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented May 21, 2024

@swift-ci Please test Linux

@ahoppen ahoppen force-pushed the dont-stack-preparation-for-editor branch from 17e9205 to 99d7a88 Compare May 21, 2024 20:18
@ahoppen
Copy link
Member Author

ahoppen commented May 21, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented May 21, 2024

@swift-ci Please test Windows

@ahoppen
Copy link
Member Author

ahoppen commented May 21, 2024

@swift-ci Please test Linux

@ahoppen
Copy link
Member Author

ahoppen commented May 21, 2024

@swift-ci Please test Windows

@ahoppen ahoppen force-pushed the dont-stack-preparation-for-editor branch from 99d7a88 to bb1529c Compare May 21, 2024 23:00
@ahoppen
Copy link
Member Author

ahoppen commented May 21, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented May 21, 2024

@swift-ci Please test Windows

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented May 21, 2024

@swift-ci Please test Windows

…task hasn't been started yet and the document is no longer active

When the user opens documents from three targets A, B, and C in quick succession, then we don’t want to schedule preparation of wait until A *and* B are finished preparing before preparing C.

Instead, we want to
- Finish for preparation of A to finish if it has already started by the time the file in C is opened. This is done so we always make progress during preparation and don’t get into a scenario where preparation is always cancelled if a user switches between two targets more quickly than it takes to prepare those targets.
- Not prepare B because it is no longer relevant and we haven’t started any progress here. Essentially, we pretend that the hop to B never happened.
@ahoppen ahoppen force-pushed the dont-stack-preparation-for-editor branch from bb1529c to 41b810b Compare May 22, 2024 01:12
@ahoppen
Copy link
Member Author

ahoppen commented May 22, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented May 22, 2024

@swift-ci Please test Windows

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented May 22, 2024

@swift-ci Please test Windows

@ahoppen ahoppen merged commit 46f5b64 into swiftlang:main May 22, 2024
3 checks passed
@ahoppen ahoppen deleted the dont-stack-preparation-for-editor branch May 22, 2024 05:03
Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +322 to +324
if inProgressPrepareForEditorTask?.id == id {
inProgressPrepareForEditorTask = nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

When is just checking document not enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

  1. You open document A and it gets prepared for editor functionality
  2. You open document B, which should cancel the preparation for A, cancellation doesn’t get checked at this exact moment, so A’s preparation continues running for a bit longer
  3. You open document A again
  4. The preparation of A from (1) finishes now and gets to this state. But the preparation of A from (3) is still running, so we can’t set inProgressPrepareForEditorTask to nil

Checking Task.isCancelled before setting inProgressPrepareForEditorTask to nil also isn’t an option because that would mean that inProgressPrepareForEditorTask got cancelled without a new preparation for editor task beings scheduled. I don’t think that can happen right now but it’s not unreasonable to assume that inProgressPrepareForEditorTask could get cancelled for whichever reason in the future.

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.

3 participants