Skip to content

Improve diagnostics deduplication - #58220

Merged
Gabriela Araujo Britto (gabritto) merged 5 commits into
mainfrom
gabritto/issue58207
Apr 26, 2024
Merged

Improve diagnostics deduplication#58220
Gabriela Araujo Britto (gabritto) merged 5 commits into
mainfrom
gabritto/issue58207

Conversation

@gabritto

@gabrittoGabriela Araujo Britto (gabritto) commented Apr 17, 2024

Copy link
Copy Markdown
Member

Fixes#58207.

Before, we only considered two diagnostics the same if everything about them was equal, including the message chain and related information. With this PR, we now consider diagnostics at the same location and with the same head message as being the same, regardless of the rest of the message chain and related information.
That is necessary because, as the new test shows, we can generate the "same" diagnostic at different moments in type checking, and they will have different elaboration (different message chains and related information).

This PR also makes it so deduplication keeps the diagnostic with more elaboration between two diagnostics considered to be equal.

Note that this doesn't completely solve the issue, because not all diagnostics that should be considered equal have the same code and head message.
Edit: follow-up PR #58318 fixes this.

@gabritto

Copy link
Copy Markdown
MemberAuthor

@typescript-bot

TypeScript Bot (typescript-bot) commented Apr 17, 2024

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

CommandStatusResults
test top400✅ Started✅ Results
user test this✅ Started✅ Results
run dt✅ Started
perf test this faster✅ Started👀 Results

@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto) Here are the results of running the user tests comparing main and refs/pull/58220/merge:

Everything looks good!

@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto)
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
MetricbaselineprDeltaBestWorstp-value
Angular - node (v18.15.0, x64)
Memory used297,009k (± 0.01%)297,007k (± 0.00%)~296,984k297,022kp=0.873 n=6
Parse Time2.71s (± 0.54%)2.71s (± 0.40%)~2.69s2.72sp=0.805 n=6
Bind Time0.82s (± 0.00%)0.82s (± 0.00%)~0.82s0.82sp=1.000 n=6
Check Time8.35s (± 0.36%)8.32s (± 0.39%)~8.26s8.35sp=0.683 n=6
Emit Time7.06s (± 0.39%)7.07s (± 0.39%)~7.05s7.12sp=0.871 n=6
Total Time18.93s (± 0.11%)18.93s (± 0.28%)~18.84s19.00sp=1.000 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used193,019k (± 0.98%)192,420k (± 0.79%)~191,766k195,511kp=1.000 n=6
Parse Time1.63s (± 1.53%)1.66s (± 1.13%)~1.62s1.67sp=0.121 n=6
Bind Time0.87s (± 1.40%)0.87s (± 0.94%)~0.86s0.88sp=1.000 n=6
Check Time11.32s (± 0.37%)11.31s (± 0.20%)~11.29s11.35sp=0.572 n=6
Emit Time3.15s (± 0.37%)3.13s (± 0.73%)~3.10s3.16sp=0.164 n=6
Total Time16.97s (± 0.33%)16.96s (± 0.28%)~16.88s17.01sp=1.000 n=6
mui-docs - node (v18.15.0, x64)
Memory used1,749,594k (± 0.00%)1,749,611k (± 0.00%)~1,749,549k1,749,680kp=0.521 n=6
Parse Time9.99s (± 0.64%)9.97s (± 0.45%)~9.91s10.04sp=0.688 n=6
Bind Time3.35s (± 0.61%)3.35s (± 0.64%)~3.33s3.39sp=0.805 n=6
Check Time82.00s (± 0.26%)81.92s (± 0.41%)~81.26s82.23sp=0.936 n=6
Emit Time0.20s (± 2.06%)0.20s (± 2.02%)~0.20s0.21sp=0.218 n=6
Total Time95.54s (± 0.24%)95.43s (± 0.36%)~94.77s95.68sp=1.000 n=6
self-build-src - node (v18.15.0, x64)
Memory used2,307,395k (± 0.01%)2,307,221k (± 0.04%)~2,305,962k2,308,279kp=0.810 n=6
Parse Time7.42s (± 0.56%)7.43s (± 0.45%)~7.39s7.49sp=1.000 n=6
Bind Time2.74s (± 0.36%)2.73s (± 0.69%)~2.71s2.76sp=0.332 n=6
Check Time49.58s (± 0.93%)49.41s (± 0.63%)~49.05s49.81sp=0.471 n=6
Emit Time3.96s (± 1.34%)4.08s (± 2.73%)+0.13s (+ 3.16%)3.95s4.24sp=0.045 n=6
Total Time63.69s (± 0.62%)63.67s (± 0.39%)~63.27s63.99sp=0.810 n=6
self-build-src-public-api - node (v18.15.0, x64)
Memory used2,382,448k (± 0.01%)2,382,950k (± 0.03%)~2,381,858k2,383,619kp=0.128 n=6
Parse Time7.65s (± 0.84%)7.66s (± 0.59%)~7.61s7.72sp=0.936 n=6
Bind Time2.51s (± 0.91%)2.51s (± 0.83%)~2.49s2.54sp=0.809 n=6
Check Time49.73s (± 0.72%)49.65s (± 0.65%)~49.27s50.15sp=0.748 n=6
Emit Time3.89s (± 2.49%)3.91s (± 2.78%)~3.81s4.11sp=0.936 n=6
Total Time63.79s (± 0.60%)63.76s (± 0.58%)~63.24s64.28sp=0.936 n=6
self-compiler - node (v18.15.0, x64)
Memory used419,464k (± 0.01%)419,484k (± 0.01%)~419,436k419,535kp=0.471 n=6
Parse Time4.23s (± 0.25%)4.21s (± 0.46%)~4.18s4.23sp=0.250 n=6
Bind Time1.60s (± 1.93%)1.60s (± 1.23%)~1.58s1.63sp=0.809 n=6
Check Time22.34s (± 0.38%)22.34s (± 0.23%)~22.26s22.40sp=0.809 n=6
Emit Time1.73s (± 1.03%)1.69s (± 2.93%)~1.64s1.77sp=0.107 n=6
Total Time29.89s (± 0.33%)29.84s (± 0.20%)~29.77s29.94sp=0.336 n=6
ts-pre-modules - node (v18.15.0, x64)
Memory used368,996k (± 0.02%)369,004k (± 0.02%)~368,931k369,168kp=1.000 n=6
Parse Time3.66s (± 0.90%)3.66s (± 0.36%)~3.64s3.68sp=0.870 n=6
Bind Time1.90s (± 1.58%)1.91s (± 1.61%)~1.87s1.94sp=0.677 n=6
Check Time19.38s (± 0.26%)19.37s (± 0.31%)~19.28s19.43sp=1.000 n=6
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)~0.00s0.00sp=1.000 n=6
Total Time24.94s (± 0.37%)24.95s (± 0.38%)~24.78s25.04sp=0.936 n=6
vscode - node (v18.15.0, x64)
Memory used2,914,727k (± 0.00%)2,914,826k (± 0.00%)~2,914,737k2,914,879kp=0.173 n=6
Parse Time13.44s (± 0.40%)13.43s (± 0.37%)~13.34s13.48sp=0.629 n=6
Bind Time4.13s (± 2.57%)4.10s (± 2.06%)~4.05s4.27sp=0.618 n=6
Check Time72.23s (± 0.52%)72.59s (± 0.32%)~72.30s72.91sp=0.093 n=6
Emit Time20.79s (±10.20%)20.15s (± 7.82%)~19.42s23.36sp=1.000 n=6
Total Time110.58s (± 1.81%)110.26s (± 1.32%)~109.48s113.19sp=0.688 n=6
webpack - node (v18.15.0, x64)
Memory used409,388k (± 0.01%)409,384k (± 0.01%)~409,312k409,441kp=0.936 n=6
Parse Time3.27s (± 0.94%)3.24s (± 0.58%)~3.21s3.26sp=0.145 n=6
Bind Time1.38s (± 0.59%)1.38s (± 0.54%)~1.37s1.39sp=0.729 n=6
Check Time14.39s (± 0.16%)14.38s (± 0.20%)~14.34s14.41sp=0.622 n=6
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)~0.00s0.00sp=1.000 n=6
Total Time19.04s (± 0.18%)19.00s (± 0.20%)~18.96s19.05sp=0.170 n=6
xstate-main - node (v18.15.0, x64)
Memory used458,720k (± 0.01%)458,689k (± 0.01%)~458,603k458,786kp=0.471 n=6
Parse Time3.22s (± 0.68%)3.22s (± 0.39%)~3.21s3.24sp=1.000 n=6
Bind Time1.17s (± 0.88%)1.17s (± 0.64%)~1.16s1.18sp=0.931 n=6
Check Time18.08s (± 0.42%)18.11s (± 0.25%)~18.03s18.16sp=0.375 n=6
Emit Time0.00s (± 0.00%)0.00s (± 0.00%)~0.00s0.00sp=1.000 n=6
Total Time22.48s (± 0.35%)22.50s (± 0.24%)~22.40s22.55sp=0.336 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
BenchmarkNameIterations
Currentpr6
Baselinebaseline6

Developer Information:

Download Benchmarks

@typescript-bot

Copy link
Copy Markdown
Contributor

Gabriela Araujo Britto (@gabritto) Here are the results of running the top 400 repos comparing main and refs/pull/58220/merge:

Everything looks good!

@jakebailey

Copy link
Copy Markdown
Member

@typescript-bot

TypeScript Bot (typescript-bot) commented Apr 17, 2024

Copy link
Copy Markdown
Contributor

Starting jobs; this comment will be updated as builds start and complete.

CommandStatusResults
run dt✅ Started✅ Results

@typescript-bot

Copy link
Copy Markdown
Contributor

Hey Jake Bailey (@jakebailey), the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.


export function sortAndDeduplicateDiagnostics<T extends Diagnostic>(diagnostics: readonly T[]): SortedReadonlyArray<T> {
return sortAndDeduplicate<T>(diagnostics, compareDiagnostics);
return sortAndDeduplicate<T>(diagnostics, compareDiagnostics, diagnosticsEqualityComparer);

@weswighamWesley Wigham (weswigham)Apr 17, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As far as I can tell, DiagnosticCollection's .add method is still using compareDiagnosticsSkipRelatedInformation, so it's just first-in-wins (with the same root message) - should that also get updated to prefer the "lesser" message like this?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

compareDiagnosticsSkipRelatedInformation is still the same in terms of what it considers equal - two diagnostics with the same location and head message but different elaboration will still be considered different by that function, and so both will be added via DiagnosticCollection.add. Only later, when we call sortAndDeduplicateDiagnostics, will we use diagnosticsEqualityComparer and get rid of all but one of the diagnostics that we now consider equal.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Now that I think about it, if we want to keep using functions like sortAndDeduplicate and insertSorted, I think we need to have two separate functions for comparison and equality: one that fully compares diagnostics for purposes of sorting (and sorting a diagnostic with more elaboration before one with less), and another for purposes of deduplication that is more permissive and only compares location and head message for equality. Otherwise we'd have to implement a function that somehow says "yes, those two diagnostics are equal, but one of them is preferred".

@gabritto
Gabriela Araujo Britto (gabritto) deleted the gabritto/issue58207 branch April 26, 2024 22:44
@microsoftMicrosoft (microsoft) locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: TeamFor Uncommitted BugPR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate diagnostics

5 participants

@gabritto@typescript-bot@jakebailey@weswigham@andrewbranch