Understanding the Go runtime

The Go runtime is an essential part of every single Go compiled binary. Understanding what it does for us and the price we pay for it can be interesting.

This talk will explore what the runtime does internally and what it provides to us.

Place
Golab #1
Length
60 min
When
November 20th, 2023
17:00

Abstract

The Go language is a powerful tool based mainly on two components: the Go compiler, which transforms our code into an executable binary, and the runtime, a big chunk of existing code compiled with our code. This talk is about the later, that piece of software that includes things like the garbage collector, the scheduler, goroutines, maps, channels...

In this talk, we will go through the explanation of what is the Go runtime and what it contains. Also, we'll talk about all the initialization processes and what does for us the runtime once everything is initialized and our code is running.

We will talk about the garbage collector and scheduler initialization, the spawn of our main function in a Go routine, and a shallow explanation of things that happen after that, like goroutines scheduling and memory management.

The talk script
Introduction

I will start by explaining what the Go runtime at a general level is, what it does (memory management, concurrency, builtin data structures...), and the cost of having it (bigger binaries, slightly slower startup process than other compiled languages, some extra runtime cost...)

Once we have settled on a general view of the runtime, I will start from the beginning, where is the Go runtime code and how it gets into our binaries. How the linking process includes our Go program plus the go runtime.

Deep dive in the initialization

After that, we going to start analyzing what happens at runtime from the exact moment the binary starts to execute until it reaches the main function.

This is the meaty part of the talk, here I going to talk about:
- The assembly code that triggers execution
- The initialization based on the operating system
- The scheduler initialization
- The heap/stack initialization
- The garbage collector initialization
- And some other small initialization bits here and there.

Here I'll cover in a certain degree of detail what implies all this initialization and why they are needed.

Deep dive in the running process

After that, we will talk about this first goroutine that will be created for our main function. I'll give a light overview of what a goroutine is and its creation process. And how it gets the goroutine for main created and executed.

Once we have our main function running, I want to explore some other things that happen while our binary is running, things like the garbage collections, goroutines parking (and preemption), and some things that are defined as part of the runtime, like maps, slices, and channels...

Finally, I'll quickly show what happens when our binary finishes its execution.

Just a quick summary of everything we have seen, some conclusions, and references to keep investigating.

Slides

Video

Made by DEVELER

GoLab is a conference made by Develer.
Develer is a company based in Campi Bisenzio, near Florence. Our motto is : "Technology to give life to your products". We produce hardware and software to create exceptional products and to improve industrial processes and people's well being.
In Develer we have passion for the new technologies and we offer our clients effective solutions that are also efficient, simple and safe for the end users. We also believe in a friendly and welcoming environment where anybody can give their contribution. This passion and this vision are what we've been driven to organize our conference "made by developers for developers".


Subscribe to our newsletter

We hate spam just as much as you do, which is why we promise to only send you relevant communications. We respect your privacy and will never share your information with third parties.
©2024 GoLab | The international conference on Go in Florence-Design & devCantiere Creativo-Made withDatoCMS