Has anyone else run into strange runtimes for Leet...
# random
d
Has anyone else run into strange runtimes for Leetcode submissions in Kotlin? I've noticed that if I use certain library methods like min or binarySearch or even properties like lastIndex, it adds a fixed overhead of roughly 10ms, as if the Leetcode JVM is loading the entire Kotlin library on-demand. Meanwhile, using the direct method like
Arrays.binarySearch
has no such overhead. Even apart from that, some problems take vastly longer in Kotlin and I can't find a reasonable explanation. In Number of Islands, for example, my Kotlin solution will take 150-200ms, but if I decompile the Kotlin bytecode back into Java and remove the few
Intrinsics
calls, suddenly it only takes 6ms. I've found no explanation within Kotlin for that kind of slowdown, and it's inconsistent between problems, so I suspect something's wrong with how the test runner is set up for Kotlin compared to Java.
e
the JVM does load classes on demand so timing a single run can have some pretty big variances
☝️ 1
d
They should probably ensure that the Kotlin stdlib is loaded before any Kotlin solution is run, there are several problems where you can clearly see about half the solutions hit 9ms and the other half hit 1ms by avoiding stdlib methods, with Leetcode indirectly discouraging using stdlib and incentivizing manually written
min
methods.