Wechat search [brain into fried fish] follow this fried fish with fried liver. In this paper, making github.com/eddycjy/blo… Already included, there are my series of articles, materials and open source Go books.

Hello, I’m fried fish.

After the release of Go1.17, we were pleasantly surprised to find that the Go language was optimized again, with compiler improvements resulting in approximately 5% performance improvements and no disruptive changes, ensuring forward compatibility.

What did he do? I don’t think I heard much about it. To that end, fish Fry explains two new proposals:

  • Proposal: Register-based Go Calling Convention
  • Proposal: Create an undefined Internal Calling Convention

This article will explain and disintegrate based on the proposal, after all, the sharing of new knowledge must be based on official data as a factual basis.

background

In previous versions of Go, the call convention for Go was simple and almost cross-platform, due to the use of the Plan9 ABi-based stack call convention, in which function arguments and return values are passed up the stack.

Plan9 and ABI are mentioned here, and these are two key concepts:

  • Plan9: the assembler used by the Go language. Rob Pike is a fierce man at bell LABS.
  • ABI: Application Binary Interface. The ABI contains the programming conventions that applications must follow when running under the operating system (e.g., Binary Interface).

The advantages and disadvantages of this scheme are as follows:

  • Advantages: simple implementation, simplified implementation cost.
  • Cons: Performance costs a lot.

As I understand it, in the early days of Go, it was easy to implement and run. Also reasonable, performance is not a TOP1 requirement.

Go1.17 optimization

What is the invocation convention

In the new version of optimizations, there is a reference to the concept of calling convention, which refers to a common agreement between the caller and the called for a function call.

The consensus includes parameters of a function, return values, the order in which parameters are passed, and how they are passed.

Both parties must follow this convention for a program function to work properly. If not, the function will not work.

What is optimization

As of Go1.17, the Go internal ABI specification (used between Go functions) will be formally changed from stack-based function argument and result passing to register-based function argument and result passing.

There are a lot of items involved in this change, and the optimization is ongoing. It was expected to be implemented on Go1.16, but was delayed on Go1.17.

Currently implemented amD64 and ARM64 architecture support. More support will continue to be available in Go1.18, see Issues #40724.

How the performance

Benchmarks with a representative set of Go packages and programs are specified in Go1.17 Release Notes.

Official figures show:

  • The Go program’s performance improved by about 5%.
  • The binary size compiled by Go is reduced by about 2%.

In terms of private data, @achille is displayed on Twitter after it is upgraded from Go1.15.7 to Go1.17. The Go1.17 upgrade on a large scale data processing system produced stunning results, and let’s take a look at his real numbers.

CPU, Malloc call time reduced by about 15% :

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

From 1.6GB to 1GB.

Combined with official and private data, the optimization effect is clear and effective. Interested partners can also test their own.

conclusion

In the new version of Go1.17, we can get some performance optimization by simply upgrading the Go version, which is great.

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

What do you think?

If you have any questions, welcome feedback and communication in the comments section. The best relationship is mutual achievement. Your praise is the biggest motivation for the creation of fried fish, thank you for your support.

This article is constantly updated. You can search “Brain into fried fish” on wechat to read it. Reply [000] There are the answers and materials for the interview algorithm of first-line big factories that I prepared. In this paper, making github.com/eddycjy/blo… Star has been included, welcome to urge more.