0

I had a performance issue when I was thinking about changing the style of the code. Previously, I liked everything to minimize, for it seemed like something to increase performance.

Example 1

new Run(path).start();

From the point of view of refactoring, it is better to write so:

Run run = new Run(path);
run.start();

So it's easier to read the code, but the question is, will I lose something because of this? Because the run is placed in the RAM?

Example 2

The line from my project (yes, creepy):

tabPane.getTabs().get(i).setUserData(Paths.get(newFile.substring(0, indexOfDifference) + name + path.toString().substring(indexOfDifference + nameOfDifference.length(), path.toString().length())));

It is difficult to read this code to a person, I understand, but if I sign every step:

String firstHalf = newFile.substring(0, indexOfDifference);
String secondHalf = path.toString().substring(indexOfDifference + nameOfDifference.length());
Path path = Paths.get(firstHalf + name + secondHalf);

tabPane.getTabs().get(i).setUserData(path);

Will I lose significant performance?

P.S. Sorry if the topic was repeated, but did not know how to write a search query.

MrChebik
  • 21
  • 6
  • Have you tried testing the performance yourself? – Taelsin Sep 01 '17 at 18:33
  • Hint: Java performance isn't decided on such subtleties. You have to understand that *anything* worth optimizing will be turned around by the JIT at runtime, based at runtime-based profiling data. Anything that the JIT doesnt optimize is not worth optimizing. You only worry about performance when you have a *real* issue, not something "assumed to be bad". And then you use a profiler to understand what happens in your application. Seriously: such questions are absolutely on the wrong level. When you really belong to the 1% of java developers that would need to worry about things on this ... – GhostCat Sep 01 '17 at 18:36
  • @Taelsin, No, if test this, need to take some not a small project, which was originally written differently, then take another option and compare performance. I think someone already knows for sure the exact answer. – MrChebik Sep 01 '17 at 18:37
  • level - then rest assured: you would not be asking such naive questions. Because then you would be studying JVM and JIT details in all depth. So again: do not waste your time worrying about performance. Instead worry about writing clean, human readable code that gets the job done in a straight forward way. And avoid getting in the way of the JIT. That is were your energy should go to. You clearly do not understand the elements that influence Java performance. So please: forget about any kind of small, micro optimization you can think of. – GhostCat Sep 01 '17 at 18:37
  • @MrChebik As said, you are going down the wrong rabbit hole. Take some serious time and digest my comments. – GhostCat Sep 01 '17 at 18:37
  • 1
    @GhostCat, thank you! – MrChebik Sep 01 '17 at 18:40

0 Answers0