Replies: 1 comment 1 reply
-
Just saw this! Very open to this change. The current algo is basically indefensible in terms of speed or quality. If you can make a PR to improve it I'd absolutely love it. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi 👋
I've been playing a bit with the code and it think we can do better on how errors (diagnostics) are matched. Right now as is, it iterates over the whole list of
tsErrorMessages
to find which ones matches the regular expressions and it's pretty expensive.So an idea,
Having this diagnostics as input:
Knowing that types are always represented in single quotes
'T'
we can remove all type information from the diagnostics. For example:This turns the input into this:
TS diagnostic chains are flatten into a single message where diagnostic messages are joined with a new line separator. This means it's easy to split them all by
\n
and trim the leading spaces:So why do this at all?
We can use the same logic above to clean args information from the tsErrorMessage keys. For instance:
Turns into:
So finding a match is
O(1)
. For instance, this could turn into something like this:In this particular case, it'll only iterate over 4 elements instead of +1000 diagnostics.
It's a simple way to generate a hash. Going further they could be converted to sha256 hashes which would probably reduce the memory footprint since keys will be smaller than the avg diagnostic message.
Of course, this doesn't cover all cases. There are a few exceptions such as this one:
...but to be fair, the current code in the repo doesn't cover this case either haha
I'll be glad to contribute. I'm just opening the discussion before opening a random PR with radical changes 😅
Beta Was this translation helpful? Give feedback.
All reactions