Does anyone know if the `lint` and `format` method...
# ktlint
g
Does anyone know if the
lint
and
format
methods provided by the
KtLintRuleEngine
are thread safe in
0.50.0
? We use these to check snippets as part of an internal tool. I was working on an upgrade this morning and was reminded that at present we're locking around these calls to prevent concurrent access, which I'm pretty sure was due to errors that we were experiencing on highly-concurrent workloads in the past. Curious whether this is known to have been resolved or whether it's tested as part of the standard
ktlint
test suites.
p
In last couple of years nothing has been changed regarding concurrency in Ktlint project itself. Also, I am not aware of any existing issues about this. So it could be interesting to know what happens if you remove your concurrency protection. Are you using ktlintRuleEngine directly or via a third party integration other than your own internal tool?
g
We're using
ktlintRuleEngine
directly, as of the recently-completed upgrade to the latest version. I know that we ran into problems with
checkstyle
(our tool does both Java and Kotlin analysis tasks). And I also believe that until recently ANTLR4 was known to not be thread-safe, although I believe that this was fixed recently. So it's possible that I noticed the
checkstyle
errors and decided to proactively single-thread
ktlint
just in case. I'll restart our workload in the next few days and keep you posted. Thanks for all of the great work on
ktlint
!
w
ktlint-gradle executes those methods in parallel via the gradle worker API
g
Thanks @wakingrufus, thats helpful. I doubt that the critical section here is that large. Even
checkstyle
which was known to be safe only failed a few times while processing ~800K small code snippets across 8 cores. So these are definitely low-probability events, and interspersed with much longer processing steps that probably make it unlikely for them to line up.