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
660
ISUCON出ようぜ!
taxio
0
66
Shutdown workers
taxio
0
220
catchup.pdf
taxio
0
55
Layered Architecture
taxio
0
93
SummerReport
taxio
0
68
ReactTutorial
taxio
0
71
ボスキタスイッチ.pdf
taxio
0
330
Other Decks in Technology
See All in Technology
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
190
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
130
強いチームと開発生産性
onk
PRO
33
11k
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
0
110
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
180
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
2
1.6k
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
200
ドメイン名の終活について - JPAAWG 7th -
mikit
33
20k
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
2
580
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
160
【若手エンジニア応援LT会】ソフトウェアを学んできた私がインフラエンジニアを目指した理由
kazushi_ohata
0
150
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
16
2.1k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
How STYLIGHT went responsive
nonsquared
95
5.2k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Writing Fast Ruby
sferik
627
61k
Designing for humans not robots
tammielis
250
25k
Side Projects
sachag
452
42k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Music & Morning Musume
bryan
46
6.2k
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. ͋Γ͕ͱ͏͍͟͝·ͨ͠