News for hackers. Stuff that matters.
Re:Java is very fast, if you don’t create many objects by jeroenhd on Monday September 12, 2022 @08:43AM (#32809274)
It's quite a paradox; Java is really fast if you keep allocations down, but Java "best practices" often involve tons of object creation.

It can also be quite hard to find out if your code will be fast or not because there are a whole bunch of rules to determine if and when your Java code will be compiled to machine code or executed through JIT. Not having a way to find out if the compiler is smart enough to cache certain values or optimize some boilerplate code away like you can with native compilers is quite annoying sometimes.

Re:Java is very fast, if you don’t create many objects by kaba0 on Monday September 12, 2022 @10:03AM (#32810415)
Java is really fast if you do plenty of allocations as well, it is cheaper to allocate on the JVM than most malloc implementations. Also, you are probably better served by writing “idiomatic” code, and only try to optimize allocation pattern if that part of the code turned up in the profiler.
Re:Java is very fast, if you don’t create many objects by golergka on Monday September 12, 2022 @08:58AM (#32809473)
> It's quite a paradox; Java is really fast if you keep allocations down, but Java "best practices" often involve tons of object creation.

That's because best practices are aimed at a task that is usually more important than performance: correctness and maintainability.

Re:Java is very fast, if you don’t create many objects by Diggsey on Monday September 12, 2022 @09:27AM (#32809868)
Yes, but the language would be better if correctness and maintainability were not so at odds with performance.
Re:Java is very fast, if you don’t create many objects by UncleMeat on Monday September 12, 2022 @09:33AM (#32809955)
It would be different. A large number of real world applications aren't especially performance sensitive and it makes sense to have tools that prioritize other things than performance. We also see how languages that do prioritize performance can suffer in other aspects (C++ is a clear example).

I think that this is fundamental in some way. Consider arithmetic. Fixed with integers suck from an ergonomics perspective. But variable-size integers are necessarily slower. Even designing something as basic as how arithmetic will work in your language forces you to consider performance against usability.

Re:Java is very fast, if you don’t create many objects by golergka on Monday September 12, 2022 @04:44PM (#32816663)
And databases would be better if consistency and availability were not so at odds with partition tolerance.
Re:Java is very fast, if you don’t create many objects by vbezhenar on Monday September 12, 2022 @09:34AM (#32809982)
It’s almost always at odds with performance.
Re:Java is very fast, if you don’t create many objects by aasasd on Monday September 12, 2022 @02:35PM (#32814788)
I'm gonna bet that vast majority of enterprise Java apps aren't so sensitive to performance. What they have is tons of business-specific logic leading to different code paths.

Accumulated business logic can be quite a heavy beast, as I learned in experience, but hundreds of `if`-s can rarely be significantly optimized with clever algos.

Re:Java is very fast, if you don’t create many objects by thargor90 on Monday September 12, 2022 @09:40AM (#32810070)
You only need to take care of object allocation count for hot paths. You can still use java "best practices" for everything around that (if they are what you want)
Re:Java is very fast, if you don’t create many objects by peter_lawrey on Wednesday September 14, 2022 @11:52PM (#32846769)
Right, it's the total object count at runtime that matters, not how many lines of code could create an object.
Re:Java is very fast, if you don’t create many objects by User23 on Monday September 12, 2022 @09:29AM (#32809889)
Interestingly this is an area where Java shows its Lisp roots. Avoiding “consing” (allocation to the heap) is a key technique for writing high performance code.
Re:Java is very fast, if you don’t create many objects by peter_lawrey on Wednesday September 14, 2022 @11:50PM (#32846757)
This is where using a profiler like YourKit or Flight Recorder is your friend. It will show you the objects that can't be optimised away and where code bottlenecks are. It's hard to determine this in advance for Java.