Skip to content

Optimize diagnostics flattening in get_all#9828

Open
integraledelebesgue wants to merge 1 commit intomainfrom
optimization/diagnostic-materialization
Open

Optimize diagnostics flattening in get_all#9828
integraledelebesgue wants to merge 1 commit intomainfrom
optimization/diagnostic-materialization

Conversation

@integraledelebesgue
Copy link
Copy Markdown
Collaborator

@integraledelebesgue integraledelebesgue commented Apr 9, 2026

Summary

Collecting the diagnostic trees into a pre-allocated vector significantly reduces the amount of intermediate allocations.
Results in a huge gain of performance in CairoLS.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

@integraledelebesgue
Copy link
Copy Markdown
Collaborator Author

integraledelebesgue commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator

@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.

@orizi made 6 comments.
Reviewable status: 0 of 1 files reviewed, 6 unresolved discussions (waiting on integraledelebesgue).


crates/cairo-lang-diagnostics/src/diagnostics.rs line 341 at r1 (raw file):

    }

    fn all_count(&self) -> usize {

move helpers to after usages.


crates/cairo-lang-diagnostics/src/diagnostics.rs line 341 at r1 (raw file):

    }

    fn all_count(&self) -> usize {

doc


crates/cairo-lang-diagnostics/src/diagnostics.rs line 345 at r1 (raw file):

    }

    pub fn extend_all_into(&self, out: &mut Vec<TEntry>) {

Suggestion:

    fn extend_all_into(&self, out: &mut Vec<TEntry>) {

crates/cairo-lang-diagnostics/src/diagnostics.rs line 345 at r1 (raw file):

    }

    pub fn extend_all_into(&self, out: &mut Vec<TEntry>) {

doc


crates/cairo-lang-diagnostics/src/diagnostics.rs line 345 at r1 (raw file):

    }

    pub fn extend_all_into(&self, out: &mut Vec<TEntry>) {

move helpers to after usages.


crates/cairo-lang-diagnostics/src/diagnostics.rs line 350 at r1 (raw file):

            subtree.extend_all_into(out);
        }
    }

if works (probably doesn't)
and than use extend directly.

Suggestion:

    pub fn iter<'a>(&'a self) -> impl Iterator<Item=&'a TEntry> {
        self.0.leaves.iter().chain(
            self.0.subtrees.iter().map(|subtree| subtree.iter()).flatten()
        )
    }

@integraledelebesgue integraledelebesgue force-pushed the optimization/diagnostic-materialization branch from 37603a6 to 31b692a Compare April 10, 2026 11:12
Copy link
Copy Markdown
Collaborator Author

@integraledelebesgue integraledelebesgue left a comment

Choose a reason for hiding this comment

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

@integraledelebesgue made 6 comments.
Reviewable status: 0 of 1 files reviewed, 6 unresolved discussions (waiting on orizi).


crates/cairo-lang-diagnostics/src/diagnostics.rs line 341 at r1 (raw file):

Previously, orizi wrote…

move helpers to after usages.

Done.


crates/cairo-lang-diagnostics/src/diagnostics.rs line 341 at r1 (raw file):

Previously, orizi wrote…

doc

Done.


crates/cairo-lang-diagnostics/src/diagnostics.rs line 345 at r1 (raw file):

Previously, orizi wrote…

doc

Done.


crates/cairo-lang-diagnostics/src/diagnostics.rs line 345 at r1 (raw file):

Previously, orizi wrote…

move helpers to after usages.

Done.


crates/cairo-lang-diagnostics/src/diagnostics.rs line 350 at r1 (raw file):

Previously, orizi wrote…

if works (probably doesn't)
and than use extend directly.

Doesn't work; rustc can't handle the generic return type in a recursive call for some reason


crates/cairo-lang-diagnostics/src/diagnostics.rs line 345 at r1 (raw file):

    }

    pub fn extend_all_into(&self, out: &mut Vec<TEntry>) {

Done.

@integraledelebesgue integraledelebesgue force-pushed the optimization/diagnostic-materialization branch from 31b692a to a2586c5 Compare April 10, 2026 13:01
Copy link
Copy Markdown
Collaborator

@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.

:lgtm:

@orizi reviewed 1 file and all commit messages, made 1 comment, and resolved 6 discussions.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on integraledelebesgue).

Copy link
Copy Markdown
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.

:lgtm:

@piotmag769 reviewed 1 file and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on integraledelebesgue).

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.

6 participants