4 ms·
The JVM starts in milliseconds Probably you're loading many thousands of classes...
by winrid 2y ago
The JVM starts in milliseconds
Probably you're loading many thousands of classes...
- mrkeen 2y agoIt certainly tells me it does. i can hit 'run unit test', sit back in my chair and zone out for 5 seconds, then come back and read that the test took 22ms.
- maccard 2y agoYeah that’s been my experience too.
- winrid 2y agohaha well your test did take 22ms, but starting the JVM and loading all the classes and all your dependency injection stuff probably took 5s. You can test it yourself with a tiny hello world, it's pretty fast to start.
- maccard 2y agoBut that's our point - you're saying java is fast (and it is ripping fast once it gets going) and the startup is fast, unless it's not.
- winrid 2y agoWell no, startup is fast, period. You're probably just giving the class loader a ton of work on startup? I would start with checking that I think. It could also be when he's hitting "run test" it's actually "compile and run"...
- maccard 2y ago> Well no, startup is fast, period. You're probably just giving the class loader a ton of work on startup? I would start with checking that I think. Ok, maybe I misspoke about the "JVM" startup. But the time between `mvn test` and it actually logging the first line of user code was in the region of 15 seconds. Every java project I've worked on has had startup time issues once they're bigger than a toy project. Saying "the JVm startup is fine, it's just the class loader that's slow" reinforces the point of "it's slow to startup" > It could also be when he's hitting "run test" it's actually "compile and run"... This would be true in C# too, and in go. Both of those tools have much quicker compilation times IME than java, which is just a nice plus.
- winrid 2y agoThat's mostly because nobody cares enough to optimize it, but if you split code into modules so your number of classes, including dependencies, is smaller, then your tests will start quickly. Usually it's dependencies and DI that's the cause of this I think. Aren't Go's compile times about the same as Java's? Of course it depends on what tooling you use to package the jars.
- winrid 2y agoBTW, I wonder if any test frameworks are using the hot reloading JVMs yet? Would also solve this problem.
- mrkeen 2y agoWell I could switch to a programming language that isn't so slowed down by ahead-of-time compilation. Maybe a JIT language?
- PhilipRoman 2y agoThanks for bringing up some painful memories. Now I'm working in C and tests take about 100ms end-to-end (multicore, no frameworks). Sometimes I re-run them for no reason just to enjoy how fast everything is.