typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Fix perfromance when there's lots of error

Open GabrielCastro opened this issue 2 weeks ago • 1 comments

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 https://github.com/microsoft/typescript-go/issues/988 . While this isn't a fix for that it allows builds to fail instead of hanging for hours

GabrielCastro avatar Dec 08 '25 23:12 GabrielCastro

This looks fine, but you should run hereby format.

jakebailey avatar Dec 08 '25 23:12 jakebailey

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.

jakebailey avatar Dec 10 '25 03:12 jakebailey

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.

jakebailey avatar Dec 10 '25 03:12 jakebailey