-
Notifications
You must be signed in to change notification settings - Fork 772
Fix perfromance when there's lots of error #2283
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
Fix perfromance when there's lots of error #2283
Conversation
DiagnosticsCollection#Add() used InsertSort, this causes a ton of memcopys on every error. This is O(n) for every error. Instead I moved the sort to lazily happen just before each GetDiagnostics call this is not only O(nlogn), but gets happen way less often than Inserts
|
This looks fine, but you should run |
internal/ast/diagnostic.go
Outdated
| c.fileDiagnostics = make(map[string][]*Diagnostic) | ||
| } | ||
| c.fileDiagnostics[fileName] = core.InsertSorted(c.fileDiagnostics[fileName], diagnostic, CompareDiagnostics) | ||
| if c.fileDiagnosticsSorted == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need sorting here as diagnostics are anyways sorted and deduplicated at end points?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's sorted so lookup can find diags later; it's a weird system but yeah
|
This turns out to be unsafe; it causes a data race when concurrently accessing processor diagnostics. We don't see the problem in main, though, only on a WIP branch I have for bringing back #2197. |
|
And, since it sorts the list on the fly, if something previously grabbed a list of diags (say, the global diags), and then they changed later, the list would potentially be concurrently modified. |
DiagnosticsCollection#Add() uses InsertSort, this causes a ton of memcopys on every error. This is O(n) for every error.
Instead I moved the sort to lazily happen just before each GetDiagnostics call this is O(nlogn), but gets happen way less often than Inserts.
This happens on codebases with lots of usages of react-hook-form due to #988 . While this isn't a fix for that it allows builds to fail instead of hanging for hours