Slide 1

Slide 1 text

RUNTIME

Slide 2

Slide 2 text

Introduction

Slide 3

Slide 3 text

Disclaimer

Slide 4

Slide 4 text

The Go RUNTIME (1.21)

Slide 5

Slide 5 text

The Compiler

Slide 6

Slide 6 text

The Go Compiler

Slide 7

Slide 7 text

The Go Compiler

Slide 8

Slide 8 text

How fast is Go? VS

Slide 9

Slide 9 text

How fast is Go? VS package main func main() {} int main() {}

Slide 10

Slide 10 text

How fast is Go? VS 1.2 MBs ~1 second/1000 executions 16 KBs ~0.3 second/1000 executions

Slide 11

Slide 11 text

How fast is Go? 75 times binary size 3 times execution time

Slide 12

Slide 12 text

Compiler ♥ Runtime

Slide 13

Slide 13 text

The compiler and the go runtime tandem

Slide 14

Slide 14 text

Hello world example package main import "fmt" func main() { fmt.Println("hello world!") }

Slide 15

Slide 15 text

Our compiled hello world The Runtime The hello world

Slide 16

Slide 16 text

Hello World Assembly 0x0000 00000 (.../main.go:5) TEXT main.main(SB), ABIInternal, $64-0 0x0000 00000 (.../main.go:5) CMPQ SP, 16(R14) 0x0004 00004 (.../main.go:5) PCDATA $0, $-2 0x0004 00004 (.../main.go:5) JLS 82 0x0006 00006 (.../main.go:5) PCDATA $0, $-1 0x0006 00006 (.../main.go:5) PUSHQ BP 0x0007 00007 (.../main.go:5) MOVQ SP, BP 0x000a 00010 (.../main.go:5) SUBQ $56, SP 0x000e 00014 (.../main.go:5) FUNCDATA $0, gclocals·g2BeySu+wFnoycgXfElmcg==(SB) 0x000e 00014 (.../main.go:5) FUNCDATA $1, gclocals·EaPwxsZ75yY1hHMVZLmk6g==(SB) 0x000e 00014 (.../main.go:5) FUNCDATA $2, main.main.stkobj(SB) 0x000e 00014 (.../main.go:6) MOVUPS X15, main..autotmp_8+40(SP) 0x0014 00020 (.../main.go:6) LEAQ type:string(SB), DX 0x001b 00027 (.../main.go:6) MOVQ DX, main..autotmp_8+40(SP) 0x0020 00032 (.../main.go:6) LEAQ main..stmp_0(SB), DX 0x0027 00039 (.../main.go:6) MOVQ DX, main..autotmp_8+48(SP) 0x002c 00044 (/usr/local/go/src/fmt/print.go:314) MOVQ os.Stdout(SB), BX 0x0033 00051 () NOP 0x0033 00051 (/usr/local/go/src/fmt/print.go:314) LEAQ go:itab.*os.File,io.Writer(SB), AX 0x003a 00058 (/usr/local/go/src/fmt/print.go:314) LEAQ main..autotmp_8+40(SP), CX 0x003f 00063 (/usr/local/go/src/fmt/print.go:314) MOVL $1, DI 0x0044 00068 (/usr/local/go/src/fmt/print.go:314) MOVQ DI, SI 0x0047 00071 (/usr/local/go/src/fmt/print.go:314) PCDATA $1, $0 0x0047 00071 (/usr/local/go/src/fmt/print.go:314) CALL fmt.Fprintln(SB) 0x004c 00076 (.../main.go:7) ADDQ $56, SP 0x0050 00080 (.../main.go:7) POPQ BP 0x0051 00081 (.../main.go:7) RET 0x0052 00082 (.../main.go:7) NOP 0x0052 00082 (.../main.go:5) PCDATA $1, $-1 0x0052 00082 (.../main.go:5) PCDATA $0, $-2 0x0052 00082 (.../main.go:5) CALL runtime.morestack_noctxt(SB) 0x0057 00087 (.../main.go:5) PCDATA $0, $-1 0x0057 00087 (.../main.go:5) JMP 0 Generated with: go build -gcflags=-S .

Slide 17

Slide 17 text

Hello World Assembly 0x0000 00000 (.../main.go:5) TEXT main.main(SB), ABIInternal, $64-0 0x0000 00000 (.../main.go:5) CMPQ SP, 16(R14) 0x0004 00004 (.../main.go:5) PCDATA $0, $-2 0x0004 00004 (.../main.go:5) JLS 82 0x0006 00006 (.../main.go:5) PCDATA $0, $-1 0x0006 00006 (.../main.go:5) PUSHQ BP 0x0007 00007 (.../main.go:5) MOVQ SP, BP 0x000a 00010 (.../main.go:5) SUBQ $56, SP 0x000e 00014 (.../main.go:5) FUNCDATA $0, gclocals·g2BeySu+wFnoycgXfElmcg==(SB) 0x000e 00014 (.../main.go:5) FUNCDATA $1, gclocals·EaPwxsZ75yY1hHMVZLmk6g==(SB) 0x000e 00014 (.../main.go:5) FUNCDATA $2, main.main.stkobj(SB) 0x000e 00014 (.../main.go:6) MOVUPS X15, main..autotmp_8+40(SP) 0x0014 00020 (.../main.go:6) LEAQ type:string(SB), DX 0x001b 00027 (.../main.go:6) MOVQ DX, main..autotmp_8+40(SP) 0x0020 00032 (.../main.go:6) LEAQ main..stmp_0(SB), DX 0x0027 00039 (.../main.go:6) MOVQ DX, main..autotmp_8+48(SP) 0x002c 00044 (/usr/local/go/src/fmt/print.go:314) MOVQ os.Stdout(SB), BX 0x0033 00051 () NOP 0x0033 00051 (/usr/local/go/src/fmt/print.go:314) LEAQ go:itab.*os.File,io.Writer(SB), AX 0x003a 00058 (/usr/local/go/src/fmt/print.go:314) LEAQ main..autotmp_8+40(SP), CX 0x003f 00063 (/usr/local/go/src/fmt/print.go:314) MOVL $1, DI 0x0044 00068 (/usr/local/go/src/fmt/print.go:314) MOVQ DI, SI 0x0047 00071 (/usr/local/go/src/fmt/print.go:314) PCDATA $1, $0 0x0047 00071 (/usr/local/go/src/fmt/print.go:314) CALL fmt.Fprintln(SB) 0x004c 00076 (.../main.go:7) ADDQ $56, SP 0x0050 00080 (.../main.go:7) POPQ BP 0x0051 00081 (.../main.go:7) RET 0x0052 00082 (.../main.go:7) NOP 0x0052 00082 (.../main.go:5) PCDATA $1, $-1 0x0052 00082 (.../main.go:5) PCDATA $0, $-2 0x0052 00082 (.../main.go:5) CALL runtime.morestack_noctxt(SB) 0x0057 00087 (.../main.go:5) PCDATA $0, $-1 0x0057 00087 (.../main.go:5) JMP 0 Generated with: go build -gcflags=-S .

Slide 18

Slide 18 text

Slices, Maps And Channels package main func main() { sampleSlice := []int{1, 2, 3, 4, 5} sampleSlice = append(sampleSlice, 6) sampleMap := map[string]int{"a": 1, "b": 2} sampleMap["c"] = 3 sampleChannel := make(chan int) for _, value := range sampleSlice { sampleChannel <- value } for _, value := range sampleMap { sampleChannel <- value } }

Slide 19

Slide 19 text

Slices, Maps And Channels Assembly 0x0077 00119 (.../main.go:5) CALL runtime.growslice(SB) 0x00e3 00227 (.../main.go:7) CALL runtime.fastrand(SB) 0x010a 00266 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0131 00305 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0158 00344 (.../main.go:8) CALL runtime.mapassign_faststr(SB) 0x016d 00365 (.../main.go:10) CALL runtime.makechan(SB) 0x0199 00409 (.../main.go:13) CALL runtime.chansend1(SB) 0x01ea 00490 (.../main.go:16) CALL runtime.mapiterinit(SB) 0x020e 00526 (.../main.go:17) CALL runtime.chansend1(SB) 0x0220 00544 (.../main.go:16) CALL runtime.mapiternext(SB) 0x0239 00569 (.../main.go:3) CALL runtime.morestack_noctxt(SB) Generated with: go build -gcflags=-S .

Slide 20

Slide 20 text

Slices, Maps And Channels package main func main() { sampleSlice := []int{1, 2, 3, 4, 5} sampleSlice = append(sampleSlice, 6) sampleMap := map[string]int{"a": 1, "b": 2} sampleMap["c"] = 3 sampleChannel := make(chan int) for _, value := range sampleSlice { sampleChannel <- value } for _, value := range sampleMap { sampleChannel <- value } }

Slide 21

Slide 21 text

Slices, Maps And Channels Assembly 0x0077 00119 (.../main.go:5) CALL runtime.growslice(SB) 0x00e3 00227 (.../main.go:7) CALL runtime.fastrand(SB) 0x010a 00266 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0131 00305 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0158 00344 (.../main.go:8) CALL runtime.mapassign_faststr(SB) 0x016d 00365 (.../main.go:10) CALL runtime.makechan(SB) 0x0199 00409 (.../main.go:13) CALL runtime.chansend1(SB) 0x01ea 00490 (.../main.go:16) CALL runtime.mapiterinit(SB) 0x020e 00526 (.../main.go:17) CALL runtime.chansend1(SB) 0x0220 00544 (.../main.go:16) CALL runtime.mapiternext(SB) 0x0239 00569 (.../main.go:3) CALL runtime.morestack_noctxt(SB) Generated with: go build -gcflags=-S .

Slide 22

Slide 22 text

Slices, Maps And Channels package main func main() { sampleSlice := []int{1, 2, 3, 4, 5} sampleSlice = append(sampleSlice, 6) sampleMap := map[string]int{"a": 1, "b": 2} sampleMap["c"] = 3 sampleChannel := make(chan int) for _, value := range sampleSlice { sampleChannel <- value } for _, value := range sampleMap { sampleChannel <- value } }

Slide 23

Slide 23 text

Slices, Maps And Channels Assembly 0x0077 00119 (.../main.go:5) CALL runtime.growslice(SB) 0x00e3 00227 (.../main.go:7) CALL runtime.fastrand(SB) 0x010a 00266 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0131 00305 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0158 00344 (.../main.go:8) CALL runtime.mapassign_faststr(SB) 0x016d 00365 (.../main.go:10) CALL runtime.makechan(SB) 0x0199 00409 (.../main.go:13) CALL runtime.chansend1(SB) 0x01ea 00490 (.../main.go:16) CALL runtime.mapiterinit(SB) 0x020e 00526 (.../main.go:17) CALL runtime.chansend1(SB) 0x0220 00544 (.../main.go:16) CALL runtime.mapiternext(SB) 0x0239 00569 (.../main.go:3) CALL runtime.morestack_noctxt(SB) Generated with: go build -gcflags=-S .

Slide 24

Slide 24 text

Slices, Maps And Channels package main func main() { sampleSlice := []int{1, 2, 3, 4, 5} sampleSlice = append(sampleSlice, 6) sampleMap := map[string]int{"a": 1, "b": 2} sampleMap["c"] = 3 sampleChannel := make(chan int) for _, value := range sampleSlice { sampleChannel <- value } for _, value := range sampleMap { sampleChannel <- value } }

Slide 25

Slide 25 text

Slices, Maps And Channels Assembly 0x0077 00119 (.../main.go:5) CALL runtime.growslice(SB) 0x00e3 00227 (.../main.go:7) CALL runtime.fastrand(SB) 0x010a 00266 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0131 00305 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0158 00344 (.../main.go:8) CALL runtime.mapassign_faststr(SB) 0x016d 00365 (.../main.go:10) CALL runtime.makechan(SB) 0x0199 00409 (.../main.go:13) CALL runtime.chansend1(SB) 0x01ea 00490 (.../main.go:16) CALL runtime.mapiterinit(SB) 0x020e 00526 (.../main.go:17) CALL runtime.chansend1(SB) 0x0220 00544 (.../main.go:16) CALL runtime.mapiternext(SB) 0x0239 00569 (.../main.go:3) CALL runtime.morestack_noctxt(SB) Generated with: go build -gcflags=-S .

Slide 26

Slide 26 text

Slices, Maps And Channels package main func main() { sampleSlice := []int{1, 2, 3, 4, 5} sampleSlice = append(sampleSlice, 6) sampleMap := map[string]int{"a": 1, "b": 2} sampleMap["c"] = 3 sampleChannel := make(chan int) for _, value := range sampleSlice { sampleChannel <- value } for _, value := range sampleMap { sampleChannel <- value } }

Slide 27

Slide 27 text

Slices, Maps And Channels Assembly 0x0077 00119 (.../main.go:5) CALL runtime.growslice(SB) 0x00e3 00227 (.../main.go:7) CALL runtime.fastrand(SB) 0x010a 00266 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0131 00305 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0158 00344 (.../main.go:8) CALL runtime.mapassign_faststr(SB) 0x016d 00365 (.../main.go:10) CALL runtime.makechan(SB) 0x0199 00409 (.../main.go:13) CALL runtime.chansend1(SB) 0x01ea 00490 (.../main.go:16) CALL runtime.mapiterinit(SB) 0x020e 00526 (.../main.go:17) CALL runtime.chansend1(SB) 0x0220 00544 (.../main.go:16) CALL runtime.mapiternext(SB) 0x0239 00569 (.../main.go:3) CALL runtime.morestack_noctxt(SB) Generated with: go build -gcflags=-S .

Slide 28

Slide 28 text

Slices, Maps And Channels package main func main() { sampleSlice := []int{1, 2, 3, 4, 5} sampleSlice = append(sampleSlice, 6) sampleMap := map[string]int{"a": 1, "b": 2} sampleMap["c"] = 3 sampleChannel := make(chan int) for _, value := range sampleSlice { sampleChannel <- value } for _, value := range sampleMap { sampleChannel <- value } }

Slide 29

Slide 29 text

Slices, Maps And Channels Assembly 0x0077 00119 (.../main.go:5) CALL runtime.growslice(SB) 0x00e3 00227 (.../main.go:7) CALL runtime.fastrand(SB) 0x010a 00266 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0131 00305 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0158 00344 (.../main.go:8) CALL runtime.mapassign_faststr(SB) 0x016d 00365 (.../main.go:10) CALL runtime.makechan(SB) 0x0199 00409 (.../main.go:13) CALL runtime.chansend1(SB) 0x01ea 00490 (.../main.go:16) CALL runtime.mapiterinit(SB) 0x020e 00526 (.../main.go:17) CALL runtime.chansend1(SB) 0x0220 00544 (.../main.go:16) CALL runtime.mapiternext(SB) 0x0239 00569 (.../main.go:3) CALL runtime.morestack_noctxt(SB) Generated with: go build -gcflags=-S .

Slide 30

Slide 30 text

Slices, Maps And Channels package main func main() { sampleSlice := []int{1, 2, 3, 4, 5} sampleSlice = append(sampleSlice, 6) sampleMap := map[string]int{"a": 1, "b": 2} sampleMap["c"] = 3 sampleChannel := make(chan int) for _, value := range sampleSlice { sampleChannel <- value } for _, value := range sampleMap { sampleChannel <- value } }

Slide 31

Slide 31 text

Slices, Maps And Channels Assembly 0x0077 00119 (.../main.go:5) CALL runtime.growslice(SB) 0x00e3 00227 (.../main.go:7) CALL runtime.fastrand(SB) 0x010a 00266 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0131 00305 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0158 00344 (.../main.go:8) CALL runtime.mapassign_faststr(SB) 0x016d 00365 (.../main.go:10) CALL runtime.makechan(SB) 0x0199 00409 (.../main.go:13) CALL runtime.chansend1(SB) 0x01ea 00490 (.../main.go:16) CALL runtime.mapiterinit(SB) 0x020e 00526 (.../main.go:17) CALL runtime.chansend1(SB) 0x0220 00544 (.../main.go:16) CALL runtime.mapiternext(SB) 0x0239 00569 (.../main.go:3) CALL runtime.morestack_noctxt(SB) Generated with: go build -gcflags=-S .

Slide 32

Slide 32 text

The Runtime

Slide 33

Slide 33 text

The runtime

Slide 34

Slide 34 text

The bootstrap process Stacks Pool TLS SYSARGS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Ps Start the World Enable GC Initial G sysmon Run Inits Your Code Start Main runtime/rt0_linux_amd64.s:7

Slide 35

Slide 35 text

The Thread Local Storage Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV Your Code Start Main INIT GC Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/sys_linux_amd64.s:637

Slide 36

Slide 36 text

Sysargs Stacks Pool TLS SYSARGS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV Your Code Start Main INIT GC Ps Start the World Enable GC Initial G sysmon Run Inits runtime/os_linux.go:232

Slide 37

Slide 37 text

OS Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV Your Code Start Main INIT GC Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/os_linux.go:346

Slide 38

Slide 38 text

The Scheduler Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV Your Code Start Main INIT GC Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/proc.go:694

Slide 39

Slide 39 text

The Scheduler ALL Ms ALL Ps ALL Gs M P SCHED M M P P

Slide 40

Slide 40 text

Stop The World Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/lockrank_on.go:309

Slide 41

Slide 41 text

Stacks Pool Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/stack.go:167

Slide 42

Slide 42 text

Memory Allocator Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/malloc.go:375

Slide 43

Slide 43 text

Memory Allocator package main func BenchmarkAlloc(b *testing.B) { slice := []int{} for 1 := 0; i < b.N; i++ { slice = make([]int, 1024) } _ = slice } int = 8 bytes, 8*1024 = 8192 8192 B/op 1 allocs/op package main func BenchmarkAlloc(b *testing.B) { slice := []int{} for 1 := 0; i < b.N; i++ { slice = make([]int, 1025) } _ = slice } int = 8 bytes, 8*1025 = 8200 ???? B/op 1 allocs/op

Slide 44

Slide 44 text

Memory Allocator package main func BenchmarkAlloc(b *testing.B) { slice := []int{} for 1 := 0; i < b.N; i++ { slice = make([]int, 1024) } _ = slice } int = 8 bytes, 8*1024 = 8192 8192 B/op 1 allocs/op package main func BenchmarkAlloc(b *testing.B) { slice := []int{} for 1 := 0; i < b.N; i++ { slice = make([]int, 1025) } _ = slice } int = 8 bytes, 8*1025 = 8200 9472 B/op 1 allocs/op

Slide 45

Slide 45 text

MSPAN 8B Memory Allocator Page (8192B) Page (8192B) Page (8192B) … MSPAN 16B Page (8192B) Page (8192B) Page (8192B) … MSPAN 24B Page (8192B) Page (8192B) Page (8192B) … MSPAN 32B Page (8192B) Page (8192B) Page (8192B) … … MSPAN 32KB Page (8192B) Page (8192B) Page (8192B) … mcache … MHEAP Mcentral 8B … Mcentral 16B Mcentral 24B Mcentral 32B Mcentral 32KB P P P

Slide 46

Slide 46 text

Memory Allocator package main func BenchmarkAlloc(b *testing.B) { slice := []int{} for 1 := 0; i < b.N; i++ { slice = make([]int, 1024*1024) } _ = slice } int = 8 bytes, 8*1024*1024 = 88388608 8388619 B/op 1 allocs/op package main func BenchmarkAlloc(b *testing.B) { slice := []int{} for 1 := 0; i < b.N; i++ { slice = make([]int, 1024*1024+1) } _ = slice } int = 8 bytes, 8*1024*1024+1 = 88388616 ??????? B/op 1 allocs/op

Slide 47

Slide 47 text

Memory Allocator package main func BenchmarkAlloc(b *testing.B) { slice := []int{} for 1 := 0; i < b.N; i++ { slice = make([]int, 1024*1024) } _ = slice } int = 8 bytes, 8*1024*1024 = 88388608 8388619 B/op 1 allocs/op package main func BenchmarkAlloc(b *testing.B) { slice := []int{} for 1 := 0; i < b.N; i++ { slice = make([]int, 1024*1024+1) } _ = slice } int = 8 bytes, 8*1024*1024+1 = 88388616 8396811 B/op 1 allocs/op

Slide 48

Slide 48 text

CPU Flags Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/proc.go:634

Slide 49

Slide 49 text

AES Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/alg.go:312

Slide 50

Slide 50 text

Random Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/proc.go:884

Slide 51

Slide 51 text

Main Thread Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/proc.go:823

Slide 52

Slide 52 text

Modules Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/symtab.go:452

Slide 53

Slide 53 text

GO Args Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/runtime1.go:72

Slide 54

Slide 54 text

GO Env Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/runtime1.go:82

Slide 55

Slide 55 text

Secure Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/security_unix.go:9

Slide 56

Slide 56 text

Debug Env Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/runtime1.go:367

Slide 57

Slide 57 text

Too much info? Take a break. Look… here is a Kitten

Slide 58

Slide 58 text

Init GC Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/mgc.go:184

Slide 59

Slide 59 text

Init GC PACER SCAVENGER Sweeper FORCEGC GC

Slide 60

Slide 60 text

Ps Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/proc.go:5183

Slide 61

Slide 61 text

Start The World Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/proc.go:1280

Slide 62

Slide 62 text

Initial G Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/proc.go:144

Slide 63

Slide 63 text

sysmon Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/proc.go:5515

Slide 64

Slide 64 text

sysmon SCAVENGER FORCEGC Netpoll Long running Gs Slow Syscalls Scheduler traces Sysmon

Slide 65

Slide 65 text

Enable GC Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/mgc.go:197

Slide 66

Slide 66 text

Run Inits Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/proc.go:248

Slide 67

Slide 67 text

Start Main Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS runtime/proc.go:266

Slide 68

Slide 68 text

Run Inits Stacks Pool TLS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Your Code Start Main Ps Start the World Enable GC Initial G sysmon Run Inits SYSARGS

Slide 69

Slide 69 text

During Runtime

Slide 70

Slide 70 text

During running

Slide 71

Slide 71 text

During running Garbage Collector Sysmon Scheduler Netpoll Your Code Ms Ps

Slide 72

Slide 72 text

During running Slices, maps and channels operations Spawn goroutine Alloc Memory

Slide 73

Slide 73 text

Summary

Slide 74

Slide 74 text

Summary Stacks Pool TLS ARGS RANDOM Run CPU Flags OS Memory Allocator AES SCHED Stop the world Main thread Modules Go ARGS GO ENV Secure DEBUG ENV INIT GC Ps Start the World Enable GC Initial G sysmon Run Inits Your Code Start Main

Slide 75

Slide 75 text

Summary 0x0077 00119 (.../main.go:5) CALL runtime.growslice(SB) 0x00e3 00227 (.../main.go:7) CALL runtime.fastrand(SB) 0x010a 00266 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0131 00305 (.../main.go:7) CALL runtime.mapassign_faststr(SB) 0x0158 00344 (.../main.go:8) CALL runtime.mapassign_faststr(SB) 0x016d 00365 (.../main.go:10) CALL runtime.makechan(SB) 0x0199 00409 (.../main.go:13) CALL runtime.chansend1(SB) 0x01ea 00490 (.../main.go:16) CALL runtime.mapiterinit(SB) 0x020e 00526 (.../main.go:17) CALL runtime.chansend1(SB) 0x0220 00544 (.../main.go:16) CALL runtime.mapiternext(SB) 0x0239 00569 (.../main.go:3) CALL runtime.morestack_noctxt(SB) Generated with: go build -gcflags=-S .

Slide 76

Slide 76 text

The Illustrations of the Talk • Made by Juan de la Cruz for this talk • Creative Commons 0 (Use it however you want) • Downloadable in Penpot (Open Source Design tool) format • https://github.com/penpot/penpot-files/raw/main/Gopher-illustrations.penpot

Slide 77

Slide 77 text

A Gift from Mattermost

Slide 78

Slide 78 text

References • Memory Allocator: https://medium.com/@ankur_anand/a-visual-guide-to-golang-memory-allocator-f rom-ground-up-e132258453ed • The Garbage collector (Maya Rosecrance): https://youtu.be/gPxFOMuhnUU?si=O9pn99sLiqptgyw3 • The GC Pacer (Madhav Jivrajani): https://youtu.be/We-8RSk4eZA?si=QNXxqq2xVEoh9At9 • The memory allocator (Andre Carvalho): https://youtu.be/3CR4UNMK_Is?si=B0bUKHohbNq73t7V • The netpoll (Cindy Sridharan): https://youtu.be/xwlo3xigknI?si=dmTrK_CH_fa0Bs51 • The scheduler (Madhav Jivrajani): https://youtu.be/wQpC99Xu1U4?si=uOu0RiLyMpNXKYa0 • Other related talks from myself: ○ The go compiler: https://youtu.be/qnmoAA0WRgE?si=ANt-Mvm4hpR9Vydx ○ About goroutines: https://youtu.be/MYtUOOizITs?si=FVGFtez2z3fNCjx7

Slide 79

Slide 79 text

CONCLUSIONS

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

Let’s Keep in touch jespinog jesus-espino jespino