You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey, while we are waiting for #616, it would be nice to get accustomed to the code base and contribution policy, send a few patches, and see how it goes in general. Improving performance without significant architectural changes seems to be a nice place to start!
So far, things I've found that can be done relatively easily:
Parser.parse visits KtFile in search for parsing errors, basically parsing it two times in a row. ~10-15% when commented out (which is not an option for a fix, but an approximation), probably a much less straightforward fix though
Avoid redundant allocations where appropriate -- mostly comes from eager materialization of PsiElement.text here and there
Avoid substringing every line four times in getMultilineTrimmedStringList (because of lines()). Less generally-applicable, helps a lot for large files with trimIndent/trimMargin (~25% on kftmt, mostly because of FormatterTest.kt which is exactly this pattern)
Avoid all the extra work in MultilineStringFormatter when there are no """ and/or trimIndent/trimMargin. ~10-15%?
Note: performance numbers are from runs on kotlinx.* libraries in sequential mode (with commented out parallelStream), parallel mode is too noisy for measurements.
Would you be okay if I gradually start sending patches for these and add @AbdullinAM as a co-reviewer?
Getting rid of redundant parse is trickier because sortedAndDistinctImports unconditionally appends \n -- meaning it changes the code structure even on perfectly-formatted code.
The good news are that the performance win will be even bigger because my duct-taped hack hasn't spotted it
Activity
hick209 commentedon May 30, 2026
Yes, please!
Those contributions would be appreciated and indeed it a good way to start getting familiarized
Avoid redundant allocations (#620)
qwwdfsad commentedon Jun 3, 2026
Getting rid of redundant
parseis trickier becausesortedAndDistinctImportsunconditionally appends\n-- meaning it changes the code structure even on perfectly-formatted code.The good news are that the performance win will be even bigger because my duct-taped hack hasn't spotted it
Reuse Parser.parse results (#622)
qwwdfsad commentedon Jul 1, 2026
Parsing twice is no longer an issue after #622, the real leftover is
getMultilineTrimmedStringList