1
search [1612f08e30ce19 brain into fried fish ] Follow this fried fish with liver-fried liver. This article GitHub github.com/eddycjy/blog has been included, and there are my series of articles, materials and open source Go books.

Hello everyone, I am fried fish.

After the release of Go1.17, we were pleasantly surprised to find that Go language has been optimized again. After the compiler is improved, it has produced a performance improvement of about 5%, and there are no destructive changes to ensure forward compatibility.

What did he do? It seems that he didn't see anyone mention it. For this reason, fried fish today will take you to interpret two new proposals:

This article will explain and disassemble based on the proposal. After all, sharing new knowledge must start from official information as a basis of fact.

background

In previous versions of Go, the calling convention of Go is simple and almost universal across platforms. The reason is that the stack calling convention based on Plan9 ABI is selected, that is, the parameters and return values of the .

Here we mentioned Plan9 and ABI altogether. These are two key concepts:

  • Plan9: The assembler used by the Go language. Rob Pike is a fierce guy at Bell Labs.
  • ABI: Application Binary Interface (application binary interface), ABI contains the programming conventions (for example: binary interface) that the application must follow when running under the operating system.

The advantages and disadvantages of this program are as follows:

  • Advantages: Simple to implement, simplifying the cost of implementation.
  • Disadvantages: A lot of price has been paid in terms of performance.

As far as I understand it, in the early days of the Go language, we adopted simple implementation first, and then talked about it after running. Also reasonable, performance is not a TOP1 requirement.

Go1.17 optimization

What is the calling convention

In the optimization of the new version, the concept of calling convention is mentioned, which refers to the consensus convention for function calls between the caller and callee of .

These consensuses include: function parameters, return values, parameter transfer order, transfer methods, etc.

When both parties must follow this agreement, the function of the program can run normally. If you don't follow it, then the function won't work.

What is optimization

Starting from Go 1.17, the Go internal ABI specification (used between Go functions) will be changed from the stack-based function parameter and result transfer method 1612f08e30d22d to the register-based function parameter and result transfer .

There are many items involved in this modification. The optimization is continuous. It was originally expected to be implemented by Go1.16, but it was dragged to Go1.17.

Currently supports amd64 and arm64 architectures. There are many more support will continue to be completed in Go1.18, the specific progress can be seen in issues #40724 .

How is the performance

is clearly pointed out in Go1.17 Release Notes 1612f08e30d2c9 that a set of benchmark tests of a representative set of Go packages and programs are used.

Official data shows:

From the perspective of private data, twitter 1612f08e30d398, indicating that it was displayed after upgrading from Go1.15.7 to Go1.17. The Go1.17 upgrade on a large-scale data processing system has produced amazing results. Let's take a look at his real data.

The call time of CPU and Malloc is reduced by about 15%:

图来自 @Achille

图来自 @Achille

The RSS size is closer to the size of the heap:

图来自 @Achille

Reduced from the original 1.6GB to 1GB.

Based on official and private data, the optimization effect is clear and effective. Interested friends can also test it by themselves.

Summarize

In the new version of Go1.17, we only need to simply upgrade the Go version by one liter, and we can get certain performance optimizations, which is very good.

From the previous stack-based function parameter and result transfer method to Go1.17~Go1.18 register-based function parameter and result transfer, the Go language is getting better step by step!

What do you think?

feedback and exchange in the comment area. The best relationship between . Your is fried fish . Thank you for your support.

Article continuously updated, can be found [micro letter head into the fried fish] read, reply [ 000 ] have an interview algorithm solution to a problem-tier manufacturers and materials prepared for me; this article GitHub github.com/eddycjy/blog been included , Welcome Star to urge you to update.

煎鱼
8.4k 声望12.8k 粉丝