Files
openide/plugins/kotlin/bundled-compiler-plugins-support
Roman Golyshev bee3ec5298 KT-65652 [kotlin] Fix freeze in KtCompilerPluginsProviderIdeImpl
The freeze was caused by a big number of modules with compiler plugins.
For each of them, we inspected the jar corresponding to the compiler plugin,
and that is an IO operation that takes time.

Since we use a multithreaded resolve, it was possible for multiple
threads to come and try to initialize the cache in `KtCompilerPluginsProviderIdeImpl`,
but only one of them could actually make progress because of `SynchronizedClearableLazy`.

The fix has three parts:

Firstly, it turns out that, in most cases, all the modules
are actually referring to the same compiler plugin jars.

So, instead of doing N jar inspections to create the
classloader for the compiler plugins' registrars,
it's better to compute the unique jars first,
and only then do the jar inspection.

Secondly, we use a faster implementation of reading a file from
the compiler plugin jar. In my local benchmark, it is approximately
50-60% faster than the previous implementation.

Thirdly, we add `checkCanceled` check before calling IO-intensive
`findCorrespondingBundledPlugin`, so that even if this freeze happens
again, at least it is possible to cancel the thread which occupies
the lock in the `SynchronizedClearableLazy`

With those changes combined, this should bring the chances of
such a freeze in a real project to a minimum

GitOrigin-RevId: 0b6865da24204a4de26d4a081462b999221d033a
2024-03-27 15:01:58 +00:00
..