Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Is the go language compiling fast?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "is the compilation speed of go language fast?", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "go language compilation speed is fast?" this article can help you solve your doubts.

Go language compilation speed is fast, the reason: 1, the use of import reference management; 2, no template compilation burden; 3, 1.5 version of the bootstrap compiler optimization; 4, fewer keywords, Go language in a total of 25 keywords, can simplify the code parsing in the compilation process.

The operating environment of this tutorial: windows10 system, GO 1.11.2, Dell G3 computer.

Now there are several main features of Go, such as compilation speed, execution speed, memory management and concurrent programming.

Why is the compilation of Go fast?

Of course, the design of the Go language is not entirely from scratch. At first, the Go team tried to design and implement a compilation front-end of the Go language, which was compiled into machine code by a C-based gcc compiler. This front-end compiler for gcc is gccgo, one of the current Go compilers.

Instead of why Go compiles fast, let's first talk about why C++ compiles slowly. C++ can also be compiled in gcc, and most of the differences in compilation speed are probably due to the language design itself.

Before discussing the problem, it is important to note that the compilation speeds compared here are all compiled statically.

The difference between static compilation and dynamic compilation

Static compilation: when compiling an executable file, the compiler extracts the link library used, packages the link into the executable file, and compiles only one executable file.

Dynamic compilation: executable files need to be accompanied by independent library files, do not pack the library to the executable file, reduce the executable file size, and then call the library during execution.

The two methods have their own advantages and disadvantages. The former does not need to manage the compatibility of different version libraries, while the latter can reduce the occupation of memory and storage (because different programs can share the same library). Which of the two methods is superior or weaker, to correspond to specific engineering problems, the default compilation mode of Go is static compilation.

Back to the question we are going to discuss: why is the compilation of C++ slow?

There are two main reasons why C++ compiles slowly:

1. Include mode of header file

2. Compilation of templates

C++ uses include to reference the header file, which will increase the number of code that needs to be compiled. For example, when the same header file is include by N files under the same project, the compiler will introduce the header file into each code, so the same header file will be compiled N times (which is unnecessary most of the time).

C++ uses templates to support generic programming, which can provide great convenience when writing different types of generic functions, but this will add a lot of unnecessary compilation burden to the compiler.

Of course C++ has a lot of follow-up optimization methods for these two problems, but for many developers, they don't want to spend too much time and energy on it.

Most later programming languages used import module instead of include in the way files were introduced.

Header file, import solves the problem of repeated compilation, of course, Go is also the way of import; in the compilation of templates, because Go follows the concept of simplicity in the design, so functional programming is not included in the design framework, so there is no time overhead caused by template compilation (no generics support is also the reason why many people are dissatisfied with Go language).

So in my opinion, Go compiles quickly for four main reasons:

1. Use the reference management method of import.

2. No compilation burden of templates

Optimization of bootstrap compiler after version 1.5

4. Fewer keywords.

There are 25 keywords in Go language:

Breakdefaultfuncinterfaceselectcasedefergomapstructchanelsegotopackageswitchconstfallthroughifrangetypecontinueforimportreturnvar

The reason why you deliberately keep so few keywords in the Go language is to simplify code parsing during compilation. Like other languages, keywords cannot be used as identifiers.

So in order to speed up the compilation, abandon C++ and switch to Go, you should also consider whether to give up the advantages of generic programming.

Note: generics may be supported in the Go 2 version.

Note:

Although Go has not yet achieved the extreme performance of C++, it is very close in most cases.

Go and Java are neck and neck in the time cost of the algorithm, but Java is much higher in terms of memory cost.

In most of the above cases, at least the time and memory cost of Go is much better than that of Python.

After reading this, the article "is the go language compiling fast?" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report