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

Smoothed diagnostics refresh to not happen for every keystroke. #6155

Merged
merged 1 commit into from
Aug 8, 2024

Conversation

orizi
Copy link
Collaborator

@orizi orizi commented Aug 6, 2024

Now only starts after previous one was done.


This change is Reviewable

@orizi orizi requested review from mkaput and removed request for mkaput August 6, 2024 15:22
@orizi orizi force-pushed the orizi/smooth-diagnostics-refresh branch from 0370f64 to a037015 Compare August 6, 2024 15:33
Copy link
Collaborator

@piotmag769 piotmag769 left a comment

Choose a reason for hiding this comment

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

Checked it and it doesn't really feel smoother from user perspective imo

Reviewable status: 0 of 1 files reviewed, all discussions resolved (waiting on @Arcticae, @Draggu, and @mkaput)

Copy link
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

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

How large was the project you used it on?
And what was the effect you've actually seen?

Reviewable status: 0 of 1 files reviewed, all discussions resolved (waiting on @Arcticae, @Draggu, and @mkaput)

Copy link
Member

@mkaput mkaput left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @Arcticae, @Draggu, and @orizi)


crates/cairo-lang-language-server/src/lib.rs line 336 at r1 (raw file):

        // Making sure only a single set refreshes diagnostics as the same time.
        // This way, following small updates to the db would not cause refreshes per sub-change.
        let _lock = self.refresh_lock.lock().await;

I'm afraid that this lock may end up being contested too heavily. Do you have a profile file generated before and after this change?

Copy link
Member

@mkaput mkaput left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @Arcticae, @Draggu, and @orizi)


crates/cairo-lang-language-server/src/lib.rs line 334 at r1 (raw file):

    #[tracing::instrument(level = "debug", skip_all)]
    async fn refresh_diagnostics(&self) -> LSPResult<()> {
        // Making sure only a single set refreshes diagnostics as the same time.

Please add a TODO comment on me to remove this lock when cancellation will be implemented (#6131)

Copy link
Member

@mkaput mkaput left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r1.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Arcticae, @Draggu, and @orizi)

Copy link
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Arcticae, @Draggu, and @mkaput)


crates/cairo-lang-language-server/src/lib.rs line 334 at r1 (raw file):

Previously, mkaput (Marek Kaput) wrote…

Please add a TODO comment on me to remove this lock when cancellation will be implemented (#6131)

even if cancellation is implemented - i'm not sure it should be removed - still no reason for a 2 diag refreshes to be running at the same time.


crates/cairo-lang-language-server/src/lib.rs line 336 at r1 (raw file):

Previously, mkaput (Marek Kaput) wrote…

I'm afraid that this lock may end up being contested too heavily. Do you have a profile file generated before and after this change?

i do not - i'm trying to find an actual example test project.
but do note this will have no actual effect currently - the db is locked all the time right after, so this basically does nothing.
we possibly may want to have only a single waiter at a point (as 2 waiters are useless, as the 2nd one would do exactly the same),.

Copy link
Member

@mkaput mkaput left a comment

Choose a reason for hiding this comment

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

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Arcticae, @Draggu, and @orizi)


crates/cairo-lang-language-server/src/lib.rs line 334 at r1 (raw file):

Previously, orizi wrote…

even if cancellation is implemented - i'm not sure it should be removed - still no reason for a 2 diag refreshes to be running at the same time.

I think it can be removed because with cancellation we'll be able to very quickly detect "oh, I'm running out-of-date DB snapshot, so I have to abandon this run", so even if this will be called in parallel, each irrelevant parallel execution will promptly terminate.

Now, this lock will indeed serialize runs of refresh_diagnostics, but each run will still do a full pass over the entire codebase which will take time even if it hits cache, and will contend for further locks.


crates/cairo-lang-language-server/src/lib.rs line 336 at r1 (raw file):

Previously, orizi wrote…

i do not - i'm trying to find an actual example test project.
but do note this will have no actual effect currently - the db is locked all the time right after, so this basically does nothing.
we possibly may want to have only a single waiter at a point (as 2 waiters are useless, as the 2nd one would do exactly the same),.

  1. Open Zeppelin Contracts are my benchmark for such things
  2. Yeah, we should use database snapshots here

@orizi orizi force-pushed the orizi/smooth-diagnostics-refresh branch from a037015 to f140ee5 Compare August 7, 2024 14:13
Copy link
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @Arcticae, @Draggu, and @mkaput)


crates/cairo-lang-language-server/src/lib.rs line 334 at r1 (raw file):

Previously, mkaput (Marek Kaput) wrote…

I think it can be removed because with cancellation we'll be able to very quickly detect "oh, I'm running out-of-date DB snapshot, so I have to abandon this run", so even if this will be called in parallel, each irrelevant parallel execution will promptly terminate.

Now, this lock will indeed serialize runs of refresh_diagnostics, but each run will still do a full pass over the entire codebase which will take time even if it hits cache, and will contend for further locks.

Done.

Copy link
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Looks much better now.

Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @Arcticae, @Draggu, and @mkaput)


crates/cairo-lang-language-server/src/lib.rs line 336 at r1 (raw file):

Previously, mkaput (Marek Kaput) wrote…
  1. Open Zeppelin Contracts are my benchmark for such things
  2. Yeah, we should use database snapshots here

Used another project - but in any case - everything looks much better.
profile comparison as well.

@orizi orizi force-pushed the orizi/smooth-diagnostics-refresh branch 2 times, most recently from 925781d to f8a78da Compare August 8, 2024 12:55
Copy link
Member

@mkaput mkaput left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 1 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Arcticae, @Draggu, and @orizi)


crates/cairo-lang-language-server/src/lib.rs line 343 at r3 (raw file):

        // together before querying the database, as well as releasing extra threads waiting to
        // start diagnostics updates. TODO(orizi): Consider removing when request
        // cancellation is supported.

Suggestion:

        // Making sure only a single thread is refreshing diagnostics at a time, and that at most
        // one thread is waiting to start refreshing. This allows changed to be grouped
        // together before querying the database, as well as releasing extra threads waiting to
        // start diagnostics updates.
        // TODO(orizi): Consider removing when request cancellation is supported.

Now only starts after previous one was done.
@orizi orizi force-pushed the orizi/smooth-diagnostics-refresh branch from f8a78da to f83dccd Compare August 8, 2024 14:50
Copy link
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on @Arcticae, @Draggu, and @mkaput)


crates/cairo-lang-language-server/src/lib.rs line 343 at r3 (raw file):

        // together before querying the database, as well as releasing extra threads waiting to
        // start diagnostics updates. TODO(orizi): Consider removing when request
        // cancellation is supported.

Done.

Copy link
Member

@mkaput mkaput left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 1 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @Arcticae and @Draggu)

@orizi orizi added this pull request to the merge queue Aug 8, 2024
Merged via the queue into main with commit 0f0f721 Aug 8, 2024
44 checks passed
@orizi orizi deleted the orizi/smooth-diagnostics-refresh branch August 12, 2024 06:15
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