4 ms·
The price one pays for the flexibility Spring offers is in terms of performance. Spring uses a lot of reflection. It makes it very slow. The startup time of Spr
by pritambarhate 9y ago
The price one pays for the flexibility Spring offers is in terms of performance. Spring uses a lot of reflection. It makes it very slow. The startup time of Spring applications tends to be around 20-30 secs. If you add Hibernate to the mix the situation becomes even worse.
Yes, Spring offers a lot of flexibility in terms of IoC and testability. I generally avoid Spring for B2C apps. (For B2C apps, I tend to favor Jersey + MyBatis) But for B2B apps and in-house enterprise apps, Spring is a very good candidate.
- djhworld 9y agoIn my experience Spring Boot apps tend to start in around 5-7 seconds. It all depends on what your init logic is I guess.
- nikanj 9y agoDuring development, you can throw money(=hardware) at the problem and get pretty decent results. In production, the startup time should not matter much, as warming of caches etc will take longer than tens of secs anyway. I guess the biggest issue is restarting services in production, but that is mostly alleviated by not having singular copies of crucial services.
- eeperson 9y agoThis is part of the reason that I highly recommend compile time dependency injection (Macwire[1], Dagger 2[2]) over runtime dependency injection (Spring, Guice). It is generally much faster. Also, if it does slow down compilation, it is a price rarely paid due to incremental compilation. [1] https://github.com/adamw/macwire https://github.com/adamw/macwire [2] https://google.github.io/dagger/ https://google.github.io/dagger/
- jacques_chester 9y ago> Spring uses a lot of reflection. It makes it very slow. The startup time of Spring applications tends to be around 20-30 secs. If you add Hibernate to the mix the situation becomes even worse. The load time of Spring apps is dominated by the number of classes loaded from disk, which is a function of the libraries pulled in. This is because the JVM loads classes out of JARs more or less linearly. Think about it for a second: which is faster, in-memory operations (reflection) or I/O (loading classes from disk)? Dave Syer has done more actual empirical investigation[0] of Spring's launchtime behaviour than anyone. If you can produce better evidence of actual behaviour, I'll be very surprised. [0] https://github.com/dsyer/spring-boot-startup-bench https://github.com/dsyer/spring-boot-startup-bench Disclosure: I work for Pivotal, we sponsor Spring development. I do not work on Spring.
- forkerenok 9y agoAvoid package scans, they are very slow.
- vbezhenar 9y agoWhile startup might be relatively slow, runtime performance should be very fast.
- stephen 9y agoSince you mentioned Hibernate, it's been years since I had to deal with it, but the "generate bytecode for all the things" start-up time of Hibernate/JPA drove me nuts and I built Joist [1] specifically to fix/avoid it. All of Joist's Rails-ish code generation (creating the boilerplate lazy-loaded getters/setters/collections/etc.) is done at build-time so your test-/server boot time is very quick. [1]: http://www.joist.ws/ http://www.joist.ws/