Home  >  Article  >  Backend Development  >  Go's performance is not as good as Java's?

Go's performance is not as good as Java's?

Go语言进阶学习
Go语言进阶学习forward
2023-07-24 14:45:281296browse

I saw a question on Zhihu today about the performance comparison between <span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;font-size: 14px;">Go</span> and <span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;font-size: 14px;">Java</span>. This kind of question There is usually only one ending, and that is endless debate. Ten years from now, if these two languages ​​​​are still alive, this may still be a hot issue:

Go's performance is not as good as Java's?

Put aside the application Talking about performance in scenarios is just a joke

At present, I mainly use Java and Go, and the direction is big data. First, let me talk about my views:

  • Most languages ​​have areas in which they are good at, and their existence is reasonable:

    • <span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;font-size: 15px;">PHP</span> Good at Building low-cost WEB is also the best language in the world

    • <span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;font-size: 15px;">c</span> Good at operating systems and embedded

    • <span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;font-size: 15px;">Go</span> Naturally high concurrency attribute

    • ##R<span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;font-size: 15px;"></span>’s scientific calculations and statistics are unparalleled

    • <span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;font-size: 15px;">Python</span> is the leader in the field of AI

    • <span style="box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;font-size: 15px;"> Java</span> Industrial-grade application services and Android (the old gangster who has long dominated the TIOBE list)

  • ##Benchmarks<span style="color: rgb(74, 74, 74);box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;"></span> The test data can certainly explain some problems, but this test environment and method are still not grounded enough. It is rare to encounter similar cases, and it will not be mentioned in actual use. Because of the gap of a few milliseconds, I changed the language and refactored the project.

  • ## Hot Code<span style="color: rgb(74, 74, 74);font-size: 16px;box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;"> This concept is very important. Some code snippets will hit once a month, then it will not How much extreme optimization is needed. </span>

  • 28<span style="color: rgb(74, 74, 74);font-size: 16px;box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;"> Rule, spend 80% of your energy on the important 20% of the code, people My energy is limited, and there are still many beautiful things in the world, such as writing original articles to share with everyone (manual wink). </span>

  • ##Talkischeap.Showme the code. Based on my experience, the current programming level of most people , it’s not my turn to talk about the performance of the language itself. If you are not, then please add me on WeChat and let me fly. <span style="color: rgb(74, 74, 74);font-size: 16px;box-sizing: border-box;background-image: initial;background-position: initial;background-size: initial;background-repeat: initial;background-attachment: initial;background-origin: initial;background-clip: initial;display: inline-block;padding-right: 2px;padding-left: 2px;line-height: 22px;"></span>

    Summary of advantages and disadvantages
I think the content replied by a friend is very objective and typical. It was caught on Zhihu and deleted.

The current problem with JAVA is not performance, because the code automatically optimized by JIT is already comparable to C.

The problem with JAVA is that in real actual projects, there are too many third-party dependencies, a bloated architecture, and over-design. At this time, it is hard to say who will win.

I personally think that because go basically only needs the standard library, the performance in actual projects is better than JAVA (Go’s coroutine is essentially an asynchronous IO model, Go language: everything is asynchronous ), in addition, resource usage is also a part of performance. Obviously go has smaller memory usage and relatively low CPU consumption.

Go on the benchmark game runs faster than Java in most scenarios, and the memory consumption is 1/3 of Java;

Let’s list the shortcomings of Go:

  1. It’s a bit anti-programmer syntax

  2. No generics

  3. The data structures in the standard library are far less rich than Java

  4. Dependency management is useless

  5. If channel is used improperly, it is very easy to deadlock

  6. Loop import is not allowed during compilation

  7. Many package names will conflict with custom variable names during coding

  8. There are many libraries that we take for granted in Java, but we find that we have to reinvent the wheel in Go

  9. The go get command will clone the entire git Warehouse, including historical commit

  10. The standard library does not provide a routine pool

  11. There is no ready-made one Future mechanism, you have to implement it yourself through channel

Those are the things that come to mind for the time being; of course all of these can be solved

Disadvantages of Java:

  1. Lack of language expression skills (a down-to-earth term is "stinky and long")

  2. High memory and CPU consumption

  3. When the heap memory is large, the garbage collector needs in-depth tuning to obtain satisfactory recycling effects; however, in some cases In scenarios with high real-time requirements, gc may simply have no solution. Once full gc is triggered, it will be hell

  4. The program needs to be warmed up

  5. The JDK is huge, and the springboot jar package is huge (the problem is most prominent under the microservice architecture)

  6. ##Spring FamilyBucket is getting heavier and heavier (for Spring, it is enough for you to do IoC AOP), resulting in poor performance of applications using FamilyBucket (please refer to the position of spring in TechEmpower Round 14), but it is still sufficient

  7. Because there are too many mature frameworks and libraries, many people are biased when they get started, thinking that programming is just adjusting APIs and using frameworks, but they know little about the principles

Those are the things that come to mind for the time being; of course, the advantages of Java far outweigh these shortcomings, otherwise it would not be ranked first in the TIOBE programming language rankings all year round

The above is the detailed content of Go's performance is not as good as Java's?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:Go语言进阶学习. If there is any infringement, please contact admin@php.cn delete