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
310
Go CLI Hands-on
taxio
0
650
ISUCON出ようぜ!
taxio
0
65
Shutdown workers
taxio
0
210
catchup.pdf
taxio
0
55
Layered Architecture
taxio
0
92
SummerReport
taxio
0
68
ReactTutorial
taxio
0
71
ボスキタスイッチ.pdf
taxio
0
330
Other Decks in Technology
See All in Technology
SREの前に
nwiizo
3
250
LINEヤフー株式会社における音声言語情報処理AI研究開発@SP/SLP研究会 2024.10.22
lycorptech_jp
PRO
2
190
AI長期記憶システム構築のための LLMマルチエージェントの取り組み / Awarefy-LLM-Multi-Agent
iktakahiro
0
130
チームを主語にしてみる / Making "Team" the Subject
ar_tama
4
330
IaC運用を楽にするためにCDK Pipelinesを導入したけど、思い通りにいかなかった話
smt7174
1
120
Amazon_CloudWatch_ログ異常検出_導入ガイド
tsujiba
4
1.7k
プロダクトチームへのSystem Risk Records導入・運用事例の紹介/Introduction and Case Studies on Implementing and Operating System Risk Records for Product Teams
taddy_919
1
200
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
3.6k
軽量DDDはもういらない! スタイルガイド本で OOPの実装パターンを学ぼう
panda_program
4
170
Observability を実現するためにアセットを活用しよう(AWS 秋の Observability 祭り ~明日使えるアセット祭り~ )
tsujiba
0
100
スプリントゴールにチームの状態も設定する背景とその効果 / Team state in sprint goals why and impact
kakehashi
2
110
AWS CodePipelineでコンテナアプリをデプロイした際に、古いイメージを自動で削除する
smt7174
1
130
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2.1k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Statistics for Hackers
jakevdp
796
220k
Why Our Code Smells
bkeepers
PRO
334
57k
What's new in Ruby 2.0
geeforr
342
31k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Designing for humans not robots
tammielis
249
25k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Git: the NoSQL Database
bkeepers
PRO
426
64k
Building Adaptive Systems
keathley
38
2.2k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
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. ͋Γ͕ͱ͏͍͟͝·ͨ͠