Hacker News new | ask | show | jobs
by mohaine 3162 days ago
To be more fair, java is mostly slow on startup which which is mostly due to:

1) Swing. I have no idea what this does on startup but it is bad. This is what killed most java GUI apps. A simple AWT or SWT app will pop open while a simple swing app will take a few seconds to get started

2) Jars on systems with virus scanners. Jars are just zip files. Many virus scanners will unzip and scan a zip on every open which leads to each jar being unziped at least 2 times and often more if the app has to load more things from the jar at a later time.

3) Spring. Really spring is just a bad idea all the way through and most of the reason people hate java is Spring. Huge XML configuration files instead of code? Spring (mostly annotations now). Stupid names like AbstractSingletonProxyFactoryBean? Spring. That aside, on startup Spring will auto generate classes which really slows things down. This could have been done during the last build but spring does it at each startup which is really slow. Spring Boot has helped with startup times but it is still slower.

After startup Spring continues to kill performance. The underling code is full of maps to control request lifecycle so instead of just calling a method it has to ask "who all is configured to do something at step PreParseRequestEncoding?" then again at ParseRequestEncoding, PostParseRequestEncoding, PrePareRequestBody, ParseRequestBody.... Not real names but the idea and number of steps is. Most of the time the answer is "nobody" but it has to ask for every step that might ever need something done.

Add on top of this JPA which is super easy but quickly breaks down to a lot of DB calls. JPA is great for people who don't want to learn SQL and simple CRUD apps but anything with any amount of data will quickly slow down to thousands of DB round trips.

5 comments

>JPA is great for people who don't want to learn SQL

That's like saying Java is for people who don't want to learn C...or C is for people who don't want to learn assembly.

It's the right tool for the right job. If you use it for everything, it's no so good.

I like Spring, I find it makes Java development pleasant, plus I have unfair access to the Spring team members by working for the same company. So I'll bite.

> Huge XML configuration files instead of code? Spring (mostly annotations now).

Spring 3, yes. Spring 4 and 5, no. XML has not been the blessed configuration approach for ~4 years.

> Stupid names like AbstractSingletonProxyFactoryBean? Spring.

Java is a language that has evolved enormously in expressiveness since Spring began, meaning heavyweight Go4 patterns were necessary early on to maintain a flexible substrate with a uniform interface serving very many use cases? Spring.

> That aside, on startup Spring will auto generate classes which really slows things down.

I believed this urban legend too.

Dave Syer, who is understandably interested in Spring criticism, has done more empirical investigation than anyone on this topic[0].

The tl;dr is that boot time is proportional to total classes loaded. That's all, that's it.

In-memory reflection operations are hilariously, stupidly, insanely faster than I/O. The JVM fetches and loads classes individually. So if you have a lot of classes, it takes a longer time to load.

The other thing to bear in mind is that Spring relies on this much less than it used to. As the language and JVM have evolved, so has Spring.

> The underling code is full of maps to control request lifecycle ... Not real names but the idea and number of steps is.

Are you talking about servlet filters? Because any web framework is going to have a few of these. Spring MVC adds a handful and all of them can be removed, replaced or added to. Spring Security adds a bunch and all of them can be removed, replaced or added to. But the defaults are chosen because of feedback, not just for the heck of it.

> Add on top of this JPA which is super easy but quickly breaks down to a lot of DB calls. JPA is great for people who don't want to learn SQL and simple CRUD apps but anything with any amount of data will quickly slow down to thousands of DB round trips.

In general, yes, I agree that JPA is a PITA. For a small to medium system I would try to avoid it where possible. For a sufficiently large codebase -- thousands of domain objects, dozens or hundreds of programmers -- it might be a necessary evil.

Mind you, if you want to see a world where the database goes from abused to outright mocked and ignored, pay a visit to Rails land. It drives me batty.

[0] https://github.com/dsyer/spring-boot-startup-bench, particularly https://github.com/dsyer/spring-boot-startup-bench/tree/mast...

I will admit that spring has gotten a lot better recently, but it is still a mess (IMHO of course) and this "benchmark" seems to agree.

The biggest issue I have with spring isn't performance but is the huge internal state that is the basis of Spring's DI.

After a few versions you end up with code that depends on bean named 'Abd" to preform a task, but in the next version is renamed to "Abc" which fixes the typo, but makes all the documentation off. And the 3 other classes that also needed that task still look for it under the name "Abd". And then the next major version replaces this entire module and the bean name is now "Xyz". To me this IS spring programming. Googling the DI names and trying them one by until you get the desired run time functionality.

I've had apps in production with unused beans defined (It only had 1 function that only throw an exception and was never called) but had to be defined or something would break. Multiple team members wasted some free time trying to locate the code that was requiring that bean but nobody could ever figure it out. At some point everybody gave up, it was easier to just let it be.

Most developers have little to no idea what is actually going on inside their spring apps (or even what half their dependencies are). When a struts like vulnerability comes along in the spring world it is going to be a massive PITA to fix. With how complex this all is I have little doubt that a vulnerability exist somewhere in there.

The Struts vulnerability was less about Struts and more about the universal difficulty of dependency management.

Which Spring Boot ameliorates by providing starter POMs. Curated, levelled, updated collections of dependencies for common cases. No need to play whack-a-dep with Maven or Gradle. No need to track 50 different dependencies yourself.

The thing is: I don't care how Spring does the magic. I care that I don't have to care.

I came to Spring and Java-for-real development relatively late -- by fluke I was on what is almost certainly the first Boot production app ever deployed, back in early 2014.

Later I got a chance to see the primordial world of Spring 3. I understand the residual hate.

> Are you talking about servlet filters? Because any web framework is going to have a few of these. Spring MVC adds a handful and all of them can be removed, replaced or added to. Spring Security adds a bunch and all of them can be removed, replaced or added to. But the defaults are chosen because of feedback, not just for the heck of it.

Even ignoring filters, it seems to me that Spring brings a lot of overhead. Adding an annotation to a method sometimes means that would appear to be a direct call between two of your beans is in fact separated by 10 method calls on a stack trace. In many cases this is not an issue (expecially in "enterprise" applications), but it is clear to me that performance is not really one of the main concerns of spring developers.

> In-memory reflection operations are hilariously, stupidly, insanely faster than I/O. The JVM fetches and loads classes individually. So if you have a lot of classes, it takes a longer time to load.

One thing that I have noticed is that with all these annotation, the Java compiler is not doing much any more. Java has effectively became a dynamic language (as in an interpreted language) where errors are only visible at runtime when hitting some specific method.

Coupled with the really slow startup time (again, I talk about Spring Boot--I get a steady 10s vs 0.01s for Go, same functionality), it makes developing a simple CRUD a pain compared to both Go or Python/Ruby...

I've never seen IntelliJ or Eclipse fail to work out how to get to the definition I'm looking for.

For Ruby I see RubyMine doing what amounts to a fulltext search. It's next to useless.

For startup time, see my notes on the JVM and the link to Dave Syer's notes.

There's also the devtools starter to ease the JVM reload pain. Which to me is by far the biggest suckiness of the thing.

> JPA

I'd like to see some reallife-ish comparisons with Jooq

I don't even know what to say about items #1 and #2 here. Unless you work for JetBrains, is Swing relevant to anything? And virus scanners shouldn't be an issue unless you're running on a Windows server, in which case I question whether you know what you're doing.

If you really believe that JPA means "you don't have to understand SQL", then you definitely don't know what you're doing.

As for Spring, I get so tired of reading lengthy critiques that boil down to:

1. "It uses XML! (or at least it did 10 years ago, when my personal experience with it was last up-to-date)"

2. "It has some classes with long names! Named after design patterns that I don't like!"

By all means, don't use Spring if you don't want to. But know that Spring is very modular, letting you include or exclude whatever you like, and the core is rather light. If you're not using at least some of it, then you're probably re-writing it... and doing a worse job than they did. Either way, stop ranting about it on web forums if your knowledge is from 2007.

> And virus scanners shouldn't be an issue unless you're running on a Windows server, in which case I question whether you know what you're doing.

Is "the server" the only place where code is run today? That is a sad image for privacy and user sovereignty. I certainly still run a lot of code on my local system, and I wish more people did the same.

I (sadly) have production experience from within the last year. I don't use Spring by choice, but it still gets forced on me by coworkers and teammates, so I reserve the right to complain.

I've heard the "you're probably re-writing it... and doing a worse job than they did" argument so many times, is this on the spring forums or something?

Not sure about using Spring for creating Web services (most use JAX-RS), but otherwise Spring is great. Not sure what we would do without it. The two major aspects are the dependency injection and just sheer number of service libraries to do anything imaginable.

I generally try to stay away from strong opinions and assume that when something has an opinion there may be a reason behind it, but in the case of Spring and Java, I have concluded that those not using or familiar with Spring are simply clueless jokers.