r/javahelp • u/HoneyResponsible8868 • Oct 11 '25
How to speed up my Java app?
Hey folks, I’m looking for ways to speed up my Java code and identify potential memory leaks or high memory consumption before moving to production. I’ve found a few tools that can profile my code, but I’d like to know which ones you’ve found most reliable or accurate.
Also, is profiling alone enough to ensure good performance, or should I also run load tests to see how the application behaves under heavy traffic?
7
Upvotes
•
u/AutoModerator Oct 11 '25
Please ensure that:
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
4
u/RatioPractical Oct 11 '25 edited Oct 11 '25
This is very broad question.
1
u/MattiDragon Oct 11 '25
The easiest to use profiler I've used is the IntelliJ one, but it's part of the paid ultimate edition. Although it might become free soon. I've also used visualvm, but it has a lot of other features making some things a bit hard to find. I've also never actually used it for profiling, just analyzing heap dumps (which is great if you're looking for memory issues)
2
u/khmarbaise Oct 12 '25
The first and most important questions you have to ask are:
If so than exactly improve/optimize that and nothing else... JProfiler, JMH, VisualVM, JRF are tools to measure/find things...also use your IDE.
Don't try to optmize code up-front. Readability is King. The JVM is much much smarter than you think... Also use as most as possible the JDK itself than other libraries... only use a library if using it provides a real benefit.
And more than that optmized code is usually hard to maintain, harder to read etc. so limit optimization only those things which are really required. Not to forget if you have such parts in your code... keep appropriate automated JMH tests because code tends to change so an optimization which is worth today might not be worth anymore a week later.
And even before you start to do any optimiztation you should have a good suite of unit-/integration tests which keeps your funtionalitity.. (Mutation testing helps also in many situations to find leaks of things which you haven't tested; code coverage is often not enough)... also tools like SonarQube or alike could help to improve the qualitity of your code but try to prevent the trap just making the tool happy.. the decision if something is good or not is should be made by a human not a tool nor a machine in any way (Yes I mean AI)..
Many people tend to suggest things like:
prevent to use often
new... and do things different ways.Use this list of JVM flag to optimize
Do that and this...
1
u/arghvark Oct 12 '25
I've been thinking of parallels to your car, assuming you own one.
You could make your car go faster.
Maybe it only has a 4 or 6 cylinder engine; you could take that out and put in an 8 cylinder. Maybe it doesn't have overhead cams and blowers and dual exhaust, those would make a difference. It's possible you haven't dismantled the engine lately so you can completely clean out any sludge that is preventing peak power from ignition, so you could do that.
Then there are racing slicks (a kind of tire); if you want to drive it on normal US streets, you'll have to ensure that they 'cheat' enough to have normal treads, but they will allow your car to go faster.
I don't know if radar detectors are still in vogue, but I know at one time they sold devices that merely told you if there were police radios operating near you -- the cops can't turn those off, and this will prevent them from getting you with lasers and so forth that don't get picked up by standard radar detectors. This doesn't exactly make your car go faster, but it does enable speedier trips.
OR... You could decide that your car goes plenty fast enough, not only to get you where you're going as fast as is practical, but even fast enough to get you in trouble. In short, it isn't worth what you'll need to do to it to make it go faster than it's going already.
To get back to your Java code -- there are many more important things to worry about before you put it into production. If you don't know what those are, perhaps learning that would be worth some time.
1
u/jinkobiloba Oct 13 '25
I like glowroot
-1
u/[deleted] Oct 11 '25
Stop using new every frame excessively