Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
go gc algorithm 101
Search
taxio
October 28, 2019
Technology
12
9k
go gc algorithm 101
Go Conference 2019 Autumn
taxio
October 28, 2019
Tweet
Share
More Decks by taxio
See All by taxio
go-gc-1
taxio
1
320
Go CLI Hands-on
taxio
0
670
ISUCON出ようぜ!
taxio
0
69
Shutdown workers
taxio
0
220
catchup.pdf
taxio
0
57
Layered Architecture
taxio
0
96
SummerReport
taxio
0
69
ReactTutorial
taxio
0
72
ボスキタスイッチ.pdf
taxio
0
340
Other Decks in Technology
See All in Technology
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
210
Amazon Kendra GenAI Index 登場でどう変わる? 評価から学ぶ最適なRAG構成
naoki_0531
0
120
DevFest 2024 Incheon / Songdo - Compose UI 조합 심화
wisemuji
0
120
Opcodeを読んでいたら何故かphp-srcを読んでいた話
murashotaro
0
270
生成AIをより賢く エンジニアのための RAG入門 - Oracle AI Jam Session #20
kutsushitaneko
4
260
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
350
AWS re:Invent 2024で発表された コードを書く開発者向け機能について
maruto
0
200
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
170
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
170
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
130
権威ドキュメントで振り返る2024 #年忘れセキュリティ2024
hirotomotaguchi
2
760
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
600
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
How GitHub (no longer) Works
holman
311
140k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
0
98
Keith and Marios Guide to Fast Websites
keithpitt
410
22k
Embracing the Ebb and Flow
colly
84
4.5k
Fireside Chat
paigeccino
34
3.1k
Building Applications with DynamoDB
mza
91
6.1k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Adopting Sorbet at Scale
ufuk
73
9.1k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
28
4.4k
The Cost Of JavaScript in 2023
addyosmani
45
7k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Transcript
©2019 Wantedly, Inc. Go GC algorithm 101 Go Conference 2019
Autumn Oct 28, 2019 - Takuma Shiotsu(@taxio_tech)
©2019 Wantedly, Inc. ࣗݾհ ‣ Wantedly. Inc. 20ଔఆऀ ‣ ژܳણҡେֶେֶӃ
M2 - ιϑτΣΞֶݚڀࣨ 5BLVNB4IJPUTV !UBYJP@UFDI
©2019 Wantedly, Inc. ✋($Λগ͠Ͱ͍ͬͯΔਓ✋
©2019 Wantedly, Inc. ✋ฉ͍ͨ͜ͱͳ͍ͱ͍͏ਓ✋
©2019 Wantedly, Inc. ✋࣮ͨ͜͠ͱ͕͋Δਓ✋
©2019 Wantedly, Inc. ຊηογϣϯͷඪ w ($ͱԿ͔ΛΔ w ϓϩϑΝΠϧ݁ՌΛோΊ͍ͯΔͱ͖ʹͳΜͱͳ͘ SVOUJNFͷ($ϑΣʔζΛײ͡औΕΔΑ͏ʹͳΔ w
3FMFBTF/PUFͷ3VOUJNFͷ߲Λ ϫΫϫΫ͠ͳ͕ΒோΊΔ͖͔͚ͬΛ࣋ͭ
©2019 Wantedly, Inc. ँࣙ w ($ʹؔ͢Δ·ͱ·ͬͨใຊʹগͳ͍ ‣ 3JDIBSE+POFT FUD ʮΨϕʔδίϨΫγϣϯࣗಈϝϞϦཧΛ
ߏ͢Δཧͱ࣮ʯ ‣ தଜ༸ FUD ʮΨϕʔδίϨΫγϣϯͷΞϧΰϦζϜͱ࣮ʯ w ॻ੶ϒϩάΛެ։͍ͯͩͬͯ͘͠͞Δํʑɼ ͦͯ͠ԿΑΓ(PͷDPOUSJCVUPSͷํʑʹਂ͘ײँ͠·͢
©2019 Wantedly, Inc. "HFOEB w ͢͜ͱ ‣ ($ͷجૅతͳཧ ‣ (PͰ࠾༻͞Ε͍ͯΔ($ΞϧΰϦζϜͷભҠͱ༰
w ͞ͳ͍͜ͱ ‣ (P͕࠾༻͍ͯ͠ͳ͍ଞͷ($ΞϧΰϦζϜ ‣ ώʔϓߏɼ"MMPDBUJPO&TDBQFղੳͷ
©2019 Wantedly, Inc. "HFOEB w ࠓͷηογϣϯͷྲྀΕ ‣ ($ͷجૅͷઆ໌ ‣ (Pͱ.BSL4XFFQ($
‣ (Pͱ$PODVSSFOU.BSL4XFFQ($ w ཧ࣮ཧ࣮ͷॱͰઆ໌͍͖ͯ͠·͢
©2019 Wantedly, Inc. *OUSPEVDUJPO
©2019 Wantedly, Inc. ($ͱʁ w (BSCBHF$PMMFDUJPO w ώʔϓྖҬʹ֬อ͞Εͨɼ ͏ΘΕͳ͍Ͱ͋Ζ͏ϝϞϦΛղ์͢Δ w
(PͰ3VOUJNFʹࡌ͞Ε͍ͯΔ
©2019 Wantedly, Inc. (PͰ w ҰఆͷλΠϛϯάͰ3VOUJNF͕($Λىಈ w runtime.GC()ͰىಈՄೳ w ($ʹӨڹΛ༩͑Δڥม
‣ GOGCɼGODEBUGʹ৭ʑ ‣ IUUQTRJJUBDPNNBUUOJUFNTFDGG
©2019 Wantedly, Inc. ($ͷجૅ༻ޠ
©2019 Wantedly, Inc. ($ͷجૅ༻ޠ w ΦϒδΣΫτ ‣ ώʔϓྖҬ͔Β֬อ͢Δ σʔλߏͷ୯Ґ ‣
ϔομΦϒδΣΫτͷϝλใ ‣ ϑΟʔϧυଞͷΦϒδΣΫτͷࢀর w ϛϡʔςʔλ ‣ ΦϒδΣΫτͷੜ "MMPDBUJPO ߋ৽Λߦ͏ )FBEFS 'JFMET
©2019 Wantedly, Inc. ($ͷجૅ༻ޠ w 3PPU ‣ ΦϒδΣΫτͷࢀরؔΛ͏ͨΊͷ࢝ ‣ TUBDLTUBUJDྖҬʹอ࣋͞ΕΔมͳͲ
‣ 3PPUʹଘࡏ͢ΔΦϒδΣΫτΛ3PPUΦϒδΣΫτͱݴ͏ w ࢮΜͰ͍ΔΦϒδΣΫτ ‣ 3PPU͔ΒḷΕͳ͍ΦϒδΣΫτ͏ΘΕͳ͍ͣ ͜ΕΛճऩ͍ͨ͠ %FBE 3PPU
©2019 Wantedly, Inc. ͭ·Γ w ($ΞϧΰϦζϜͱ͍͏ͷɼ ‣ ࢮΜͰ͍Δੜ͖͍ͯΔΦϒδΣΫτΛͲ͏ݟ͚ͯɼ Ͳ͏ղ์͍ͯ͘͠ͷ͔ ‣
ಈ͖ଓ͚ΔϛϡʔςʔλͱͲ͏͍͏࿈ܞΛऔΔͷ͔ w ධՁ࣠ ‣ -BUFODZϛϡʔςʔλͷ ࠷େ ఀࢭ࣌ؒ ‣ 5ISPVHIQVU୯Ґ࣌ؒ͋ͨΓͷώʔϓαΠζॲཧೳྗ ‣ ଞʹώʔϓྖҬͷঢ়ଶʹ͍͔ؔͯͭ͘͠
©2019 Wantedly, Inc. ۩ମతͳ($ΞϧΰϦζϜ
©2019 Wantedly, Inc. .BSL4XFFQ($ w ʹൃද͞Εͨ࠷ॳͷ($ΞϧΰϦζϜ ‣ +PIO.D$BSUIZ 3FDVSTJWFGVODUJPOTPGTZNCPMJDFYQSFTTJPOTBOE UIFJSDPNQVUBUJPOCZNBDIJOF
$PNNVOJDBUJPOPGUIF"$. "QS w ͭͷϑΣʔζ͔ΒΔ ‣ ੜ͖͍ͯΔΦϒδΣΫτΛ୳͢.BSLϑΣʔζ ‣ ࢮΜͰ͍ΔΦϒδΣΫτΛճऩ ղ์ ͢Δ4XFFQϑΣʔζ w ($͕ىಈ͔ͯ͠Βऴྃ͢Δ·Ͱɼϛϡʔςʔλಈ࡞͠ͳ͍ ‣ 458 4UPQ5IF8PSME ‣ ͜Ε͕MBUFODZͷओͳཁҼ
©2019 Wantedly, Inc. .BSLϑΣʔζ w ੜ͖͍ͯΔΦϒδΣΫτΛݟ͚ͭΔϑΣʔζ w 3PPU͔Β୳ࡧ͍͖ͯ͠ɼ ݟ͚ͭͨΦϒδΣΫτͷϔομʹ.BSLΛ͚͍ͯ͘ ✔
✔ ✔ Root
©2019 Wantedly, Inc. 4XFFQϑΣʔζ w ࢮΜͰ͍ΔΦϒδΣΫτΛճऩ͢ΔϑΣʔζ w ώʔϓྖҬΛ͔Β୳ࡧ w .BSLͷ͍͍ͯͳ͍ΦϒδΣΫτΛճऩ
‣ ࣍ͷ"MMPDBUJPOʹ͏ͨΊͷ४උ ‣ ྫ͑GSFFͳPCKFDUΛཧ͓ͯ͘͠ϦετʹՃ ✔ ✔ ✔ Heap
©2019 Wantedly, Inc. .BSL4XFFQ($ w ϝϦοτ ‣ ୯७Ͱൺֱత࣮͕؆୯ w σϝϦοτ
‣ ϝϞϦͷஅยԽ ϑϥάϝϯςʔγϣϯ ‣ ͳ"MMPDBUJPO ‣ 458ͷӨڹͰMBUFODZ͕େ͖͍
©2019 Wantedly, Inc. (Pͱ.BSL4XFFQ($ w (P·Ͱओʹ͜ͷΞϧΰϦζϜ w લճͷ($ͰNBSLͨ͠ੜଘΦϒδΣΫτͷ૯αΠζ
GOGC ͷϝϞϦ͕৽͘͠"MMPDBUF͞Εͨͱ͖ʹىಈ ‣ NBSLࡁΈ૯αΠζͷॳظ.# ‣ GOGC=offͷ߹($ىಈ͠ͳ͍ w ͪΖΜ͜Ε͚ͩͩͱ͍ͷͰɼ ͍͕ͭ͘Γࠐ·Ε͍ͯΔ ‣ #JUNBQNBSLJOH 1BSBMMFMJNQM 5$.BMMPD FUD
©2019 Wantedly, Inc. #JUNBQNBSLJOH w ΦϒδΣΫτͷϔομʹ.BSLΛ͚ΔͷͰͳ͘ɼ ผͷྖҬʹ·ͱΊ͓ͯ͘ ‣ 4XFFQ࣌ͷ͕ࠪ͘ͳΔ ‣
.BSLϑϥάΛ͢ͷָ͕ ‣ $PQZPO8SJUFͱͷ૬ੑ͕͍͍
©2019 Wantedly, Inc. ͔͠͠458ͷӨڹͰ MBUFODZ͕େ͖͍
©2019 Wantedly, Inc. ͦͦͳͥ458͕ඞཁʁ w ($தʹϛϡʔςʔλ͕ΦϒδΣΫτͷࢀরߏΛม͑ͯ ͠·͏ͱɼ߹ੑΛอূͰ͖ͳ͍ ྫ͑...
©2019 Wantedly, Inc. $PODVSSFOU .BSL4XFFQ($
©2019 Wantedly, Inc. $PODVSSFOU.BSL4XFFQ($ w ϛϡʔςʔλͱ($Λฒߦʹಈ࡞ͤ͞Δ w ຬ͖ͨ͢ਖ਼ੑ ‣ গͳ͘ͱ3PPU͔Β౸ୡՄೳͳશͯͷPCKFDU͕
ࣦΘΕͳ͍Α͏ʹ͢Δ ‣ ࠷ऴతʹ($Λྃ͢Δ w Ͳ͏ͬͯ͜ΕΒΛຬͨ͠ͳ͕Βฒߦ࣮ߦ͢Δͷ͔ʁ ‣ ৭NBSLJOH ‣ 8SJUFCBSSJFS
©2019 Wantedly, Inc. ৭NBSLJOH w PCKFDUʹͭͷঢ়ଶΛఆٛ ศ্ٓɼ৭Ͱදݱ ‣ നະ୳ࡧ
NBSLແ͠ ‣ փ୳ࡧத NBSLࡁΈϦετʹೖΕ͓ͯ͘ ‣ ࠇ୳ࡧࡁΈ NBSLࡁΈϦετʹແ͍ w Ϧετ͔ΒΦϒδΣΫτͷࢀরΛऔΓग़͠ɼ ͦͷGJFMEΛ୳ࡧ͍ͯ͘͠ ‣ (PͰRVFVFͱ࣮ͯ͠͞Ε͍ͯΔ Root
©2019 Wantedly, Inc. 8SJUFCBSSJFS w ΦϒδΣΫτ͕໎ࢠʹͳΔ݅ ‣ ϛϡʔςʔλ͕നΦϒδΣΫτͷϙΠϯλΛ ࠇΦϒδΣΫτʹॻ͖ࠐΉ
શͯͷփ৭ΦϒδΣΫτ͔Βͷɼ ͦͷനΦϒδΣΫτͷܦ࿏͕ଘࡏ͠ͳ͍ w ͜ͷ͕݅ୡ͞Εͳ͍Α͏ʹ ϛϡʔςʔλͷΦϒδΣΫτૢ࡞ʹҰఆͷॲཧΛڬΉ ‣ ৭ʑͳख๏͕͋Δ ‣ (P͕࠾༻͍ͯ͠Δख๏ޙͰղઆ
©2019 Wantedly, Inc. $PODVSSFOU.BSL4XFFQ($ w େɼҎԼͷϑΣʔζ͔ΒΔ ‣ .BSLTFUVQ 458
3PPUΦϒδΣΫτΛશͯփ৭ʹృΔ SVOUJNFͷ($ʹඞཁͳ͋Ε͜ΕͷॳظԽ ‣ $PODVSSFOUNBSL ‣ .BSLUFSNJOBUJPO 458 ඞཁͳ߹3PPUΛ࠶ࠪ ‣ $PODVSSFOUTXFFQ ‣ 4XFFQUFSNJOBUJPO 458
©2019 Wantedly, Inc. $PODVSSFOU.BSL4XFFQ($ w ϝϦοτ ‣ 458ݮʹΑͬͯMBUFODZ͕ݮΔ w σϝϦοτ
‣ 8SJUFCBSSJFSʹΑͬͯεϧʔϓοτ͕Լ͕Δ
©2019 Wantedly, Inc. (PͰͷ࣮
©2019 Wantedly, Inc. (Pͷ$PODVSSFOU($࣮ͷྺ࢙ w "VH (P (BSCBHF$PMMFDUJPO ($ 1MBOBOE3PBENBQ
‣ IUUQTEPDTHPPHMFDPNEPDVNFOUE :*TO/3$/.Y/;D:9;-PWS)WW-I,@I,/XP50 w (P ‣ $PODVSSFOU4XFFQ w (P ‣ $PODVSSFOU.BSL 8SJUFCBSSJFS ‣ $PODVSSFOU($ w (P ‣ 8SJUFCBSSJFSվྑ Ͱվྑྃ 1SPQPTBMFMJNJOBUFSFTDBO
©2019 Wantedly, Inc. $PODVSSFOU($ಋೖ݁Ռ w MBUFODZ͕େ෯ʹݮͬͨ 'SPN3JDL)VETPO IUUQTUBMLTHPMBOHPSHHPHDQEG Q (PQIFS$PO%FOWFS
+VMZ
©2019 Wantedly, Inc. (Pͷ8SJUFCBSSJFS w "MMPDBUJPO࣌ ‣ ৽֬͘͠อ͞ΕͨΦϒδΣΫτΛͪʹࠇʹృΔ Root ৽ΦϒδΣΫτ
©2019 Wantedly, Inc. (Pͷ8SJUFCBSSJFS w "MMPDBUJPO࣌ ‣ ৽֬͘͠อ͞ΕͨΦϒδΣΫτΛͪʹࠇʹృΔ Root ৽ΦϒδΣΫτ
©2019 Wantedly, Inc. (Pͷ8SJUFCBSSJFS w ΦϒδΣΫτͷࢀরؔΛॻ͖͑ͨͱ͖ ‣ ࢀর͞Ε͍ͯͨ͞Ε͍ͯΔΦϒδΣΫτͷ྆ํΛփ৭ʹృΔ ‣ ͢ͰʹNBSL͞Ε͍ͯΔ
փPSࠇ ߹Կ͠ͳ͍ Ͳ͔͔͜Βͷࢀর
©2019 Wantedly, Inc. (Pͷ8SJUFCBSSJFS w ΦϒδΣΫτͷࢀরؔΛॻ͖͑ͨͱ͖ ‣ ࢀর͞Ε͍ͯͨ͞Ε͍ͯΔΦϒδΣΫτͷ྆ํΛփ৭ʹృΔ ‣ ͢ͰʹNBSL͞Ε͍ͯΔ
փPSࠇ ߹Կ͠ͳ͍ Ͳ͔͔͜Βͷࢀর
©2019 Wantedly, Inc. (Pͷ8SJUFCBSSJFS w ΦϒδΣΫτͷࢀরؔΛॻ͖͑ͨͱ͖ ‣ ࢀর͞Ε͍ͯͨ͞Ε͍ͯΔΦϒδΣΫτͷ྆ํΛփ৭ʹృΔ ‣ ͢ͰʹNBSL͞Ε͍ͯΔ
փPSࠇ ߹Կ͠ͳ͍ Ͳ͔͔͜Βͷࢀর
©2019 Wantedly, Inc. (Pͷ8SJUFCBSSJFS w ($։࢝࣌ʹࢮΜͰ͍ΔΦϒδΣΫτΛճऩ͢Δ ‣ ($ऴྃ࣌ʹࢮΜͰ͍ΔΦϒδΣΫτ͕ଘࡏ͠ͳ͍อূແ͍ ‣ %JKLTUSBTUZMFͱ:VBTBTUZMFͷϋΠϒϦου
w SFGHJUIVCDPNHPMBOHHPCMPCFBTSD SVOUJNFNCBSSJFSHP
©2019 Wantedly, Inc. (Pͷ$PODVSSFOU($ w ϑΣʔζ 4XFFQUFSNJOBUJPO .BSLTFUVQ
.BSL .BSLUFSNJOBUJPO 4XFFQ w SFGHJUIVCDPNHPMBOHHPCMPCFBTSD SVOUJNFNHDHP
©2019 Wantedly, Inc. 4XFFQUFSNJOBUJPO w લճͷ4XFFQ͕ऴΘ͍ͬͯͳ͍߹ɼ 458Λͨ͠͏͑Ͱ4XFFQϑΣʔζΛऴΘΒͤΔ
©2019 Wantedly, Inc. .BSLTFUVQ w 458 w ॳظԽ ‣ gcphase_GCoff_GCmark
‣ 8SJUFCBSSJFS༗ޮԽ ‣ "TTJTU༗ޮԽ w 3PPUΦϒδΣΫτΛશͯփ৭ʹృΔ
©2019 Wantedly, Inc. .BSL w ($༻ͷHPSPVUJOF͕NBSLJOH͍ͯ͘͠ w .BSLJOHΑΓ"MMPDBUJPOͷ͕ૣ͍߹ɼ "TTJTU༻ͷHPSPVUJOF͕ىಈ͢Δ
©2019 Wantedly, Inc. .BSLUFSNJOBUJPO w 458 w NBSLϑΣʔζͷޙॲཧ ‣ gcphase_GCmark_GCmarktermination
‣ "TTJTUͳͲͷແޮԽ ‣ ࣍ͷ($ىಈ༻ͷώʔϓαΠζΛࢉग़
©2019 Wantedly, Inc. 4XFFQ w લॲཧ ‣ gcphase_GCmarktermination_GCoff ‣ 8SJUFCBSSJFSΛແޮԽ
w (P5$.BMMPDΛϕʔεͱͨ͠"MMPDBUJPOػߏ ‣ ίϨΫλ͕·ͩݟ͍ͯͳ͍ྖҬʹΦϒδΣΫτΛ֬อ͠ͳ͍Α ͏ʹɼ"MMPDBUJPO͢ΔલʹͦͷαΠζͷQBHFͷTXFFQॲཧΛ ਐΊ͓ͯ͘ ɾɾɾ ͜͜·ͰͷྖҬͳΒ നΦϒδΣΫτΛ֬อͯ͠େৎ Heap (Page)
©2019 Wantedly, Inc. Ͱͦͷઌʁ
©2019 Wantedly, Inc. ະདྷͷ(P($ w ($ΞϧΰϦζϜɼύϥμΠϜଞʹ·ͩ·ͩ͋Δ w ੈผ($Λಋೖ͍ͨ͠ͱ͍͏͋Δ ‣ 3JDL
IUUQTCMPHHPMBOHPSHJTNNLFZOPUF *4.. ‣ ϨΠςϯγԼ͕Δ͕8SJUFCBSSJFSʹΑͬͯɼ εϧʔϓοτ͕Լ͕ΔՄೳੑ͕͋Δ w ۩ମతͳٞ·ͩݟͨΒͳ͍ ݟ͚ͭͯͳ͍ ͕ɼ (PͳͲͰͲ͏มΘָ͍͔͕ͬͯ͘͠Έ
©2019 Wantedly, Inc. ·ͱΊ w $PODVSSFOU.BSL4XFFQ($Λ࠾༻͍ͯ͠Δ ‣ ($ىಈத($༻ͷHPSPVUJOF͕࡞ಈ͍ͯ͠Δ w ($ͷىಈλΠϛϯάڥมGOGCͰௐՄೳ
w ($͠ଓ͚͍ͯΔ ‣ 3FMFBTFOPUF1SPQPTBMΛಡΉͷָ͕͠ΈͰ͢Ͷ
©2019 Wantedly, Inc. ͋Γ͕ͱ͏͍͟͝·ͨ͠