# Profile Kotlin compilation with gradle

**URL:** <https://discuss.kotlinlang.org/t/profile-kotlin-compilation-with-gradle/20415>\
**Category:** Support\
**Created:** [January 2, 2021, 2:52pm UTC](https://discuss.kotlinlang.org/t/profile-kotlin-compilation-with-gradle/20415 "2021-01-02T14:52:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hanslovsky](https://avatars.discourse-cdn.com/v4/letter/h/eb8c5e/32.png) [@hanslovsky](https://discuss.kotlinlang.org/u/hanslovsky)\
**Post date:** [January 2, 2021, 2:52pm UTC](https://discuss.kotlinlang.org/t/profile-kotlin-compilation-with-gradle/20415/1 "2021-01-02T14:52:27Z")

</div>

I am working on a Kotlin [project](https://github.com/saalfeldlab/imklib2) that takes surprisingly long to compile and I would like to figure out what takes so long. The project has about 16500 lines of Kotlin code and takes about 2 minutes to compile on my laptop (Ryzen 7 4570U, 32GB Ram). I already identified a few possible culprits but have not seen dramatic improvements so far:

- Reduce number of classes drastically (went from over 4000 (lots of inline lambdas) down to a few hundred)
- Split up code into more but smaller files
- Upgrade from kotlin version `1.3.72` to `1.4.21` (that actually made it a little slower)

The project adds extension functions and operator overloading to a Java image processing library that makes extensive use of recursive generics. I could imagine that those recursive generics pose a significant challenge to the compiler.

Is there an option to profile the time spent on individual files/classes/functions with the Kotlin compiler or, even better, gradle?

---

<div class="post-metadata">

**Author:** ![hanslovsky](https://avatars.discourse-cdn.com/v4/letter/h/eb8c5e/32.png) [@hanslovsky](https://discuss.kotlinlang.org/u/hanslovsky)\
**Post date:** [January 2, 2021, 3:04pm UTC](https://discuss.kotlinlang.org/t/profile-kotlin-compilation-with-gradle/20415/2 "2021-01-02T15:04:59Z")

</div>

I found the `--scan` option just after creating this post, which does exactly what I need. 🤦‍♂️  
Well, hopefully this thread will be useful to others who are looking for a similar thing

edit: Actually, it does not give me per-file insights, unfortunately.
