I have a JsonPath multiplatform library that perfo...
# multiplatform
e
I have a JsonPath multiplatform library that performs very well on JVM. It's only external dependency is kotlinx serialization. I just tried running it in native (
runReleaseExecutableLinuxX64
) and it is approx 4-5x slower than the JVM version. What's the best way to profile it and figure out why it's running so slow?
There are a lot of short lived objects; could the GC be having issues with that? It's also pretty slow on js, but I think js is actually running faster than native 🤔
c
It might not be a specific bottleneck caused by some API method, but just generally that the JVM is extremely optimized and its runtime is very efficient, which isn’t quite the same with Native or other targets. The JVM has a slow start, but once it’s been running for a short while it becomes nearly as fast as native binaries. Native code, generally, does typically run faster than JVM apps, but in this case Kotlin Native has its own runtime environment which is relatively new and isn’t nearly as highly optimized as the JVM. It’s not really expected to perform better than JVM apps at this time, though admittedly I don’t think it’s normally that much slower. 4-5x does seem quite excessive. Short-lived objects could definitely be part of the issue, especially since it has a brand new GC. I recall in one of their blog posts about it that they’re focusing on correctness first, and will tackle GC performance later. Also, you might want to try setting up some profiler tests in GitHub Actions on various OSs, to see if it’s related to the OS.
e
It seems like it could be it because running the benchmark once looks like native is equal to or faster than JVM. But running it 80k times causes the average to increase 5x in most cases. And running it 80k times on cases that result in looping through each run multiple times seems to degrade roughly linearly.
I'm also going to start running my benchmarks through GitHub and target Linux, mac, and Windows
Hopefully they won't time out 😅