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

perf: Segregate syntax and semantic diagnostics #17775

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

ShoyuVanilla
Copy link
Member

Closes #17731

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 2, 2024
.attach_first_edition(file_id)
.unwrap_or_else(|| EditionedFileId::current_edition(file_id));

// [#3434] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily.
Copy link
Member Author

Choose a reason for hiding this comment

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

Previous comment was pointing the wrong issue no.34344

/// due to macros.
pub fn diagnostics(
pub fn semantic_diagnostics(
Copy link
Member Author

Choose a reason for hiding this comment

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

Calling db.parses once in fn syntax_diagnotics(..) and again in this function that previously only called once in fn diagnotics(..) is a bit reluctant, but I think that it won't harm perf much due to lru cache here;

pub trait SourceDatabase: FileLoader + std::fmt::Debug {
/// Parses the file into the syntax tree.
#[salsa::lru]
fn parse(&self, file_id: EditionedFileId) -> Parse<ast::SourceFile>;

Comment on lines 558 to 560
let slice2 = slice.clone();
self.task_pool.handle.spawn(ThreadIntent::LatencySensitive, {
let snapshot = self.snapshot();
let subscriptions = subscriptions.clone();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let slice2 = slice.clone();
self.task_pool.handle.spawn(ThreadIntent::LatencySensitive, {
let snapshot = self.snapshot();
let subscriptions = subscriptions.clone();
self.task_pool.handle.spawn(ThreadIntent::LatencySensitive, {
let snapshot = self.snapshot();
let subscriptions = subscriptions.clone();
let slice = slice.clone();

no need to come up with a new name then

))
}
});
self.task_pool.handle.spawn(ThreadIntent::LatencySensitive, {
Copy link
Member

Choose a reason for hiding this comment

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

This duplicates the amount of tasks we do now, it also spawns semantic and parser diagnostics tasks in lockstep which means we might push queue up some syntax diagnostic tasks after semantic ones. I think a better way to model this might be having the DiagnosticsTaskKind::Syntax spawn the corresponding semantic one once its finished computing. That way we make sure to first do the syntax ones.

Copy link
Member Author

Choose a reason for hiding this comment

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

it also spawns semantic and parser diagnostics tasks in lockstep which means we might push queue up some syntax diagnostic tasks after semantic ones.

That's terrible I couldn't think about it 😅
I think that with TaskPool::spawn_with_sender, I can publish two tasks in order within a single job

@ShoyuVanilla
Copy link
Member Author

Since the syntax and the semantic diagnostics are always called in serial order, I think that it might be better to rollback the segregation
of original diagnostics function and just add a callback as a parameter of it to get result of syntax diagnostics before semantic ones 🤔

@Veykril
Copy link
Member

Veykril commented Aug 5, 2024

Thanks!
@bors r+

@bors
Copy link
Collaborator

bors commented Aug 5, 2024

📌 Commit eea1e9b has been approved by Veykril

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Aug 5, 2024

⌛ Testing commit eea1e9b with merge f62d7b9...

@bors
Copy link
Collaborator

bors commented Aug 5, 2024

☀️ Test successful - checks-actions
Approved by: Veykril
Pushing f62d7b9 to master...

@bors bors merged commit f62d7b9 into rust-lang:master Aug 5, 2024
11 checks passed
@ShoyuVanilla ShoyuVanilla deleted the segregate-diags branch August 5, 2024 19:51
@Veykril
Copy link
Member

Veykril commented Aug 7, 2024

This seems to have broken diagnostics 😅 I don't get any native ones at all anymore

})
{
// don't signal an update if the diagnostics are the same
return;
Copy link
Member

Choose a reason for hiding this comment

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

This should be a continue now

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, yes, indeed 🥲 terrible mistake. I'll fix this one or two hours later once I got home

bors added a commit that referenced this pull request Aug 7, 2024
fix: Native diagnostics not working

              This should be a `continue` now

_Originally posted by `@Veykril` in #17775 (comment)

I've tested the release compile output with IDE in the original PR, but my test workspace had only one `.rs` file 🤦 😢
@Veykril
Copy link
Member

Veykril commented Aug 8, 2024

Alright this works great (aside from that one small issue 😄), syntax errors in hir/lib.rs are instantaneous now (where as they took a good second before)

lnicola pushed a commit to lnicola/rust that referenced this pull request Aug 13, 2024
fix: Native diagnostics not working

              This should be a `continue` now

_Originally posted by `@Veykril` in rust-lang/rust-analyzer#17775 (comment)

I've tested the release compile output with IDE in the original PR, but my test workspace had only one `.rs` file 🤦 😢
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Publish diagnostics in two rounds
4 participants