Make ktfmt up to 100x faster via native-image#584
Conversation
|
Hi @sgammon! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
ktfmt native imagektfmt up to 185x faster via native-image
ktfmt up to 185x faster via native-imagektfmt up to 100x faster via native-image
This comment was marked as outdated.
This comment was marked as outdated.
|
I don't work at facebook and am not a maintainer on this project. I just filed that FR 🙃 |
This comment was marked as outdated.
This comment was marked as outdated.
|
yeah I meant to react to the PR description, accidentally did the wrong one 🙈 |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
hick209
left a comment
There was a problem hiding this comment.
Initial batch. There shall be more tomorrow 😃
Here are my initial comments. No need to act on anything just yet if you do not desire.
hick209
left a comment
There was a problem hiding this comment.
It's honestly a lot of things I don't really understand here.
From my limited understanding this seems like a good improvement and I'm tempted to just merge it in and give it a go.
Right now I see there some CI jobs (here from GH) failed, could you take a look to see if any of that makes sense before I pull this in for internal review?
|
Was this PR abandoned? 😢 |
|
@eduardb not abandoned, no, just trying to figure out windows CI; meta must facilitate windows and mac CI in order to support this on all operating systems. we have offered to provide those CI services at our own cost. i will be updating this to match |
2a88504 to
32953b7
Compare
|
if, in the meantime, any community members would like |
|
Is the build break there expected? Not the CodeQL one, that one seem broken for all commits, so don't worry |
|
@hick209 now the only broken step is codeql |
7bd349a to
58d7bbb
Compare
|
@hick209 OK, I have split it up, rebased, and cleaned it up a bit:
|
| branches: | ||
| - main | ||
| - feat/native-image |
There was a problem hiding this comment.
We only plan to keep the main branch, so I guess we can drop this here, right?
There was a problem hiding this comment.
Yes, this is a temporary commit only, so that testing can happen on my fork; I can make sure the build is green before pinging you for a build approval
|
Nice! It looks much better / cleaner now! Thank you |
|
@hick209 has imported this pull request. If you are a Meta employee, you can view this in D108930075. |
Native ktfmt
Introduces support for a native binary version of
ktfmt, via GraalVMnative-image; no code changes have taken place, just build changes, in order to make kotlinc's infrastructure (which ktfmt depends on) usable under SVM, Substrate Virtual Machine.After some optimization and cleanup, I have some initial numbers which show promising gains:
The native version of
ktfmtis identical in every way to the regular JVM version, except it is built AOT, and, since it is already machine code, it does not need a JVM installed at runtime.We have been using this version of ktfmt internally for some time now -- a few weeks -- and it is stable for us even on codebases with hundreds or thousands of files. Once you hit many thousands of files, the performance gap between JVM and SVM begins to close (this is tunable). That makes sense, considering JVM's warmed-up JIT state is still known to beat SVM at peak performance.
However, for smaller executions of ktfmt -- particularly ones which only format changed code -- the difference can be quite persuasive toward native, because of essentially instant startup time.
Note: To actually ship this on ktfmt, we are going to need build infrastructure for each target OS/architecture pair. GraalVM's support matrix currently includes:
I am able to build
ktfmtfor each of the above targets, and have CI (personally) to help, but will need to transition that stuff to GHA and Meta's control. In conversations with Nivaldo (@hick209), he indicated CI should be no problem.Fixes and closes #441 cc / @ZacSweers
Trying it out
Here are pre-built binaries for Linux amd64 and macOS arm64, if you'd like to try it out. Each package comes with
ktfmtandktfmt-build-report.html, which is a standalone file you can open in your browser. It shows the full contents of the native image and various stats about its contents.Download for macOS arm64
Download for Linux amd64
The final compressed packages end up at about
13MBfor macOS and16MBfor Linux.