-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Very slow startup: can this be mitigated? #211
Comments
Hi, thank you report. It's really interesting stuff Your assessment is correct: the first execution is indeed longer than later ones. The numbers and the difference may not be entirely accurate, as many factors can influence this. There are mainly two reasons why the first computation is slower. And yeah, you're right, it's a lazy initialization in the following way:
It is not possible to eliminate or speed up the native library loading process. This behavior is inherent to the JVM itself. You can use a pure kotlin implementation — You can also pre-load the native library in advance by calling If it is critical for you to measure performance, including the first computation, I recommend using PS: Kotlin has a convenient function |
Wouldn't be so sure about that.
|
@hakanai I think you must have accidentally included the library load time in whatever timing you did. I bet if you do a "warm up" computation (which will force the libraries to load) then try your computation with timing, the default+native numbers will drop below the kotlin one. When I tested that way, the prediction above was borne out as described. I was definitely seeing 20s or so of load time for native libraries, and and after excluding that they outperformed the kotlin native code. |
After observing the first computation done by multik's arrays seemed slow, I was surprised that the following toy script
reliably resulted in results on this order when run in intellij:
Before I knew the magnitude of the difference between the first item and the rest I was writing it off as some sort of cacheing effect. But now it really seems like it's some sort of lazy initialization or JIT compiling or something that has nothing to do with the computation at hand.
Can this be mitigated? I tried with both 0.2.2 and 0.2.3 with the same results. My laptop is an M1 chip mac, but I'm ultimately interested in running it with ubuntu distros.
Thanks in advance for your advice.
New info:
Running the same test on an ubuntu instance, it does seem like the delay is magnitudes smaller there (only 0.2s). Maybe this is something to do with my laptop architecture or something.
The text was updated successfully, but these errors were encountered: