fix: very slow string replacement in large declaration files #561
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, we've been using this great tool for a long time, but recently we observed it takes a lot of time to run the plugin.
The plugin was running on our codebase for
20s
.After whole afternoon spend on rewriting the project to regular expresions to replace ts compiler and AST lookup I've found out that what is acutally slow is replacement of the types in the declaration file 🤡
Turns out
slice
/substring
toghether with concatenation and allocating new string in each iteration is very slow on long strings as it has to copy all characters multiple times.ChatGTP suggested the solution, and as a result it now takes just
1s
to run the plugin 🥳My poc with regexps was even faster, I mean extraction was faster and it overall took 500ms, but traversing AST is defenitely easier to maintain, so I gave up on that.
Btw tests on
main
are failing, I'm not sure how to proceed.before
after