Skip to content

perf: fast comparison using FullSpan and source code#1737

Merged
belav merged 2 commits intobelav:mainfrom
TimothyMakkison:compare_full_span
Dec 25, 2025
Merged

perf: fast comparison using FullSpan and source code#1737
belav merged 2 commits intobelav:mainfrom
TimothyMakkison:compare_full_span

Conversation

@TimothyMakkison
Copy link
Copy Markdown
Contributor

@TimothyMakkison TimothyMakkison commented Nov 4, 2025

  • Compare the old and formatted code before using SyntaxNodeComparer (ie new version of csharpier, no changes but hash is cache is invalidated)
  • Skip comparison if two TypeDeclaration aka (classes, struct, interfaces etc) or MethodDeclaration are identical
    • This could be done for all SyntaxNodes but may slow things down if most nodes have changed

The CLI spends up to 30% of the time doing comparisons, with this, we can skip cases with identical source code, and only compare types/methods that have changed. The performance degradation for lots of changes (i.e. first time a project is formatted) shouldn't be that great as CompareFullSpan is basically a fast SequenceEqual and only used for type declarations and methods.

Copy link
Copy Markdown
Owner

@belav belav left a comment

Choose a reason for hiding this comment

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

Looks good!

@belav belav added this to the 1.3.0 milestone Dec 25, 2025
@belav belav merged commit 387e6ee into belav:main Dec 25, 2025
7 checks passed
belav added a commit that referenced this pull request Dec 31, 2025
- Compare the old and formatted code before using `SyntaxNodeComparer`
(ie new version of csharpier, no changes but hash is cache is
invalidated)
- Skip comparison if two `TypeDeclaration` aka (classes, struct,
interfaces etc) or `MethodDeclaration` are identical
- This could be done for all `SyntaxNodes` but may slow things down if
most nodes have changed

The CLI spends up to 30% of the time doing comparisons, with this, we
can skip cases with identical source code, and only compare
types/methods that have changed. The performance degradation for lots of
changes (i.e. first time a project is formatted) shouldn't be that great
as `CompareFullSpan` is basically a fast `SequenceEqual` and only used
for type declarations and methods.

Co-authored-by: Bela VanderVoort <[email protected]>
belav added a commit that referenced this pull request Feb 20, 2026
- Compare the old and formatted code before using `SyntaxNodeComparer`
(ie new version of csharpier, no changes but hash is cache is
invalidated)
- Skip comparison if two `TypeDeclaration` aka (classes, struct,
interfaces etc) or `MethodDeclaration` are identical
- This could be done for all `SyntaxNodes` but may slow things down if
most nodes have changed

The CLI spends up to 30% of the time doing comparisons, with this, we
can skip cases with identical source code, and only compare
types/methods that have changed. The performance degradation for lots of
changes (i.e. first time a project is formatted) shouldn't be that great
as `CompareFullSpan` is basically a fast `SequenceEqual` and only used
for type declarations and methods.

Co-authored-by: Bela VanderVoort <[email protected]>
belav added a commit that referenced this pull request Mar 12, 2026
- Compare the old and formatted code before using `SyntaxNodeComparer`
(ie new version of csharpier, no changes but hash is cache is
invalidated)
- Skip comparison if two `TypeDeclaration` aka (classes, struct,
interfaces etc) or `MethodDeclaration` are identical
- This could be done for all `SyntaxNodes` but may slow things down if
most nodes have changed

The CLI spends up to 30% of the time doing comparisons, with this, we
can skip cases with identical source code, and only compare
types/methods that have changed. The performance degradation for lots of
changes (i.e. first time a project is formatted) shouldn't be that great
as `CompareFullSpan` is basically a fast `SequenceEqual` and only used
for type declarations and methods.

Co-authored-by: Bela VanderVoort <[email protected]>
belav added a commit that referenced this pull request Apr 4, 2026
- Compare the old and formatted code before using `SyntaxNodeComparer`
(ie new version of csharpier, no changes but hash is cache is
invalidated)
- Skip comparison if two `TypeDeclaration` aka (classes, struct,
interfaces etc) or `MethodDeclaration` are identical
- This could be done for all `SyntaxNodes` but may slow things down if
most nodes have changed

The CLI spends up to 30% of the time doing comparisons, with this, we
can skip cases with identical source code, and only compare
types/methods that have changed. The performance degradation for lots of
changes (i.e. first time a project is formatted) shouldn't be that great
as `CompareFullSpan` is basically a fast `SequenceEqual` and only used
for type declarations and methods.

Co-authored-by: Bela VanderVoort <[email protected]>
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.

2 participants