Slide 1

Slide 1 text

Bengo4.com, Inc. Understanding Go GC Kaito Tsutsui

Slide 2

Slide 2 text

About Our Company 2

Slide 3

Slide 3 text

Bengo4.com,Inc. VISION まだないやり方で、世界を前へ。 Drive a paradigm shift for the better world. MISSION 「プロフェッショナル・テック 」で、次の常識をつくる。 Be the Professional-Tech Company. プロフェッショナルだからできること。専門知とテクノロジーで、社会に貢献する。

Slide 4

Slide 4 text

Bengo4.com, Inc. OUR SERVICE 4 税理士に無料で相談・検索できる日本最大級の 税務相談ポータルサイト 最新の法改正や実務について分かりやすく解説する 日本最大級の企業法務ポータルサイト 日本最大級の無料法律相談ポータルサイト 時事問題の弁護士解説を中心としたメディア 弁護士事務所、企業法務職向け人材紹介事業 AI基盤技術「 LegalBrain 1.0」を組み込んだ リーガル特化型 AIエージェント 契約の締結から管理までデジタルで完結させる 契約マネジメントプラットフォーム

Slide 5

Slide 5 text

Go Garbage Collector 5

Slide 6

Slide 6 text

Bengo4.com, Inc. What is GC? A garbage collector is a system that recycles memory on behalf of the application by identifying which parts of memory are no longer needed. – A Guide to the Go Garbage Collector 6

Slide 7

Slide 7 text

Bengo4.com, Inc. What is GC? A garbage collector is a system that recycles memory on behalf of the application by identifying which parts of memory are no longer needed. – A Guide to the Go Garbage Collector 7

Slide 8

Slide 8 text

Bengo4.com, Inc. Example 8

Slide 9

Slide 9 text

Bengo4.com, Inc. go run main.go 9

Slide 10

Slide 10 text

Bengo4.com, Inc. GOGC=50 go run main.go 10

Slide 11

Slide 11 text

Bengo4.com, Inc. GOGC 11 GOGC sets next cycle’s target heap size after each GC GOGC↑ ● NumGC decreases ● Memory usage increases GOGC↓ ● NumGC increases ● Memory usage decreases

Slide 12

Slide 12 text

How GC works in Go 12

Slide 13

Slide 13 text

Bengo4.com, Inc. Mark and Sweep (Go ~1.4) 13 Root

Slide 14

Slide 14 text

Bengo4.com, Inc. Mark 14 Root Mark and Sweep (Go ~1.4)

Slide 15

Slide 15 text

Bengo4.com, Inc. Stop-the-world 15 Root Mark and Sweep (Go ~1.4)

Slide 16

Slide 16 text

Bengo4.com, Inc. Sweep 16 Root Mark and Sweep (Go ~1.4)

Slide 17

Slide 17 text

Bengo4.com, Inc. Concurrent Mark and Sweep (Go 1.5~) ● Tri-color Marking ○ Marks with 3 colors (white, black, and grey) ● Write Barrier ○ Prevents missed references 17

Slide 18

Slide 18 text

Bengo4.com, Inc. ● White: initial state or unreachable ● Grey: reachable but uncompleted ● Black: reachable and marked Concurrent Mark and Sweep (Go 1.5~) 18 p 1 2 3 Root Queue

Slide 19

Slide 19 text

Bengo4.com, Inc. ● White: initial state or unreachable ● Grey: reachable but uncompleted ● Black: reachable and marked Concurrent Mark and Sweep (Go 1.5~) 19 p 1 2 3 Root Queue p

Slide 20

Slide 20 text

Bengo4.com, Inc. ● White: initial state or unreachable ● Grey: reachable but uncompleted ● Black: reachable and marked Concurrent Mark and Sweep (Go 1.5~) 20 p 1 2 3 Root Queue p 1

Slide 21

Slide 21 text

Bengo4.com, Inc. ● White: initial state or unreachable ● Grey: reachable but uncompleted ● Black: reachable and marked Concurrent Mark and Sweep (Go 1.5~) 21 p 1 2 3 Root Queue p 1 2

Slide 22

Slide 22 text

Bengo4.com, Inc. ● White: initial state or unreachable ● Grey: reachable but uncompleted ● Black: reachable and marked Concurrent Mark and Sweep (Go 1.5~) 22 p 1 2 3 Root Queue p 1 2 3

Slide 23

Slide 23 text

Bengo4.com, Inc. ● White: initial state or unreachable ● Grey: reachable but uncompleted ● Black: reachable and marked Concurrent Mark and Sweep (Go 1.5~) 23 p 1 2 3 Root Queue p 1 2 3

Slide 24

Slide 24 text

Bengo4.com, Inc. ● White: initial state or unreachable ● Grey: reachable but uncompleted ● Black: reachable and marked Concurrent Mark and Sweep (Go 1.5~) 24 p 1 2 3 Root Queue 1 2 3

Slide 25

Slide 25 text

Bengo4.com, Inc. ● White: initial state or unreachable ● Grey: reachable but uncompleted ● Black: reachable and marked Concurrent Mark and Sweep (Go 1.5~) 25 p 1 2 3 Root Queue 2 3

Slide 26

Slide 26 text

Bengo4.com, Inc. ● White: initial state or unreachable ● Grey: reachable but uncompleted ● Black: reachable and marked Concurrent Mark and Sweep (Go 1.5~) 26 p 1 2 3 Root Queue 3

Slide 27

Slide 27 text

Bengo4.com, Inc. ● White: initial state or unreachable ● Grey: reachable but uncompleted ● Black: reachable and marked Concurrent Mark and Sweep (Go 1.5~) 27 p 1 2 3 Root Queue

Slide 28

Slide 28 text

Bengo4.com, Inc. ● White: initial state or unreachable ● Grey: reachable but uncompleted ● Black: reachable and marked Concurrent Mark and Sweep (Go 1.5~) 28 p 1 2 3 Root Queue

Slide 29

Slide 29 text

Bengo4.com, Inc. Green Tea GC (Go 1.25 Experimental) 29

Slide 30

Slide 30 text

Bengo4.com, Inc. Takeaways ● Learned the value of studying the runtime to write better code ● Inspired to keep learning as Go keeps evolving ● Looking forward to the future of Go 30

Slide 31

Slide 31 text

Bengo4.com, Inc. ● A Guide to the Go Garbage Collector ● Why Go's Garbage Collection is a Game Changer ● mgc.go ● GoのGCについて理解する ● GoのGC(Garbage Collection)入門 ● GoのGCを10分で学ぼう ● GoのGCなどで見かける3色マーキング Bibliography 31