Does the design template use slow Java code?

Does Java development code use slow code? If I use additional interfaces and syntax constructs (for example, class wrapping), will I get well-organized, but slow code, or does this not make my code much slower?

+8
java performance design-patterns
source share
7 answers

This will not make your code much slower. Since some function calls are wrapped in additional classes or methods, some method calls are slightly slower, but the person does not notice this. This is about nanoseconds. Allways prefers the advantage of well-read and reusable code.

I am a high-performance application, you should consider reorganizing your code for better performance after designing and implementing it based on templates. But normal is not necessary.

And as always: it depends on the template used and the use of your program.

+11
source share

According to your point of view, you should never use Java primarily because it is full of abstraction layers, which makes it more convenient to write correct and supported code, but reduces its speed below assembly or C. If you are worried about that wrappers make your code much slower, you probably have a use case that will make C more suitable than Java.

On the other hand, you should definitely take care not to reconfigure and drop truck with templates for every problem that you see in your code. Use templates wisely where you can clearly see the benefits, not just where you see the template theoretically fit.

The way I prefer to code is to first make the simplest, dumbest solution that solves my immediate problem. If later I have to add one or two more similar functions, which will lead to code duplication or other code smells, only then I will think about introducing an appropriate template.

+3
source share

Interfaces make your code more understandable and easier to change in the future, but do not affect the speed, because they exist only to tell the compiler how your code fits together.

Design pattern templates are usually solutions to common problems. If you have a problem, use one of the known solutions. Will this make your program slower? It depends on the choice between the available solutions. You need to understand the tradeoffs of each template in order to choose a choice.

But without using a design template solution, you use your own DIY home solution; when we do this, we, as a rule, will not solve the problem, either quickly (in our time and in computer time), or, as is clear, for future maintenance. This last point is that design patterns give us a new way to talk about problems and solutions. Once we understand this new dictionary, we can more easily solve more complex problems.

So do they make your program slower? No, they make it work. Faster.

Enjoy reading the pictures. They make more sense if you have a real problem to solve.

+1
source share

As already mentioned, the overhead of using design patterns is negligible, and of course, just take a look at the source code for some java projects that require execution, like android, and you will be surprised that they all use highly developed patterns.

However, some coud design options affect performance, for example, they prefer to use List instead of hashmap, where the map is more suitable.

0
source share

Ideally, when using authorized software constructs, you should not worry about performance. JVM is able to optimize the code. Most performance problems usually arise in code where we write code related to thread synchronization and where we do I / O, such as database calls. Having a few additional interfaces and classes to make your design modular and accurate will not hurt. You may need to be careful if you write your own frameworks that rely on the use of reflections and other advanced features, if you do it in an optimal way, you can risk performance bottlenecks.

0
source share

In most cases, additional code processing makes the code a little slower. But in some cases this is not so. If you iterate over> 1 billion iterations, extra packaging can be significantly slower. Good practice is to write good, readable and reusable code first. And only after that try to profile and optimize the code, is there worse performance. Often you need to change the calculation algorithm, but sometimes you need to write workaround code.

0
source share

May be. As usual, there are no easy answers when it comes to compromise.

You’ve found that using a specific template will make the code clearer, but this can happen at the cost of a performance penalty. So what are you doing? You use your best judgment. Often this can be to try the template first, and then check to see if it is fast enough and then optimize as needed. Sometimes you already know that it should be as fast as possible, or vice versa, that the code is not performance critical.

0
source share

All Articles