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
DateTime parsing slow in Spring Boot #40078
Comments
There's no Spring Boot code involved in this, so I'm not sure what we can do about that? Also, your approach to benchmarking is flawed. You should use something like JMH. |
This is the Spring code involved:
|
Measuring the total time it takes to do the parsing should be just fine, We don't need JMH to see that it takes longer time running the parsing code in Spring compared to plain java. |
This isn't an apples-to-apples comparison and, like @mhalbritter, I don't think it has anything to do with Spring. When you run the code directly in plain Java, the JVM is in a different state to when the code's run as part of a Spring application. For example, the amount of heap that's available will be different and this will have a knock-on effect on garbage collection. The code that you're measuring creates a significant amount of gargage that has to be collected. When there's less heap available, this collection will have to be performed more often which will slow things down. You could see this for yourself by running with |
Parsing datetime strings when running Spring Boot is slow compared to plain Java.
Please look at my example code below.
Is this performance degradation using Spring a bug, or is it normal that Spring have this much overhead?
The Spring perfomance is better with Temurin 21 compared to Temurin 17, but still slow compared to plain java.
Prerequisite:
Using a Spring Boot 3.2.3 demo created with Spring Initializr.
Running examples with IntelliJ IDEA 2023.3.6
Code example used with Spring Boot and with plain Java project:
Measurements:
Spring Boot 3.2.3 - Java Temurin 17
Total parse time ms: 9330
Spring Boot 3.2.3 - Java Temurin 21:
Total parse time ms: 4225
Plain Java project - Java Temurin 17
Total parse time ms: 1547
Plain Java project - Java Temurin 21:
Total parse time ms: 1648
The text was updated successfully, but these errors were encountered: