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
成果を出しながら成長する、アウトプット駆動のキャッチアップ術 / Output-driven catch-up techniques to grow while producing results
aiandrox
0
280
開発生産性向上! 育成を「改善」と捉えるエンジニア育成戦略
shoota
2
330
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
150
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
330
宇宙ベンチャーにおける最近の情シス取り組みについて
axelmizu
0
110
Oracle Cloudの生成AIサービスって実際どこまで使えるの? エンジニア目線で試してみた
minorun365
PRO
4
280
UI State設計とテスト方針
rmakiyama
2
510
ずっと昔に Star をつけたはずの思い出せない GitHub リポジトリを見つけたい!
rokuosan
0
150
サーバレスアプリ開発者向けアップデートをキャッチアップしてきた #AWSreInvent #regrowth_fuk
drumnistnakano
0
190
PHP ユーザのための OpenTelemetry 入門 / phpcon2024-opentelemetry
shin1x1
1
190
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
130
PHPからGoへのマイグレーション for DMMアフィリエイト
yabakokobayashi
1
170
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Done Done
chrislema
181
16k
Documentation Writing (for coders)
carmenintech
66
4.5k
4 Signs Your Business is Dying
shpigford
181
21k
What's in a price? How to price your products and services
michaelherold
243
12k
RailsConf 2023
tenderlove
29
940
A Tale of Four Properties
chriscoyier
157
23k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Practical Orchestrator
shlominoach
186
10k
Raft: Consensus for Rubyists
vanstee
137
6.7k
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. ͋Γ͕ͱ͏͍͟͝·ͨ͠