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 Lambdaと歩んだ“サーバーレス”と今後 #lambda_10years
yoshidashingo
1
180
『Firebase Dynamic Links終了に備える』 FlutterアプリでのAdjust導入とDeeplink最適化
techiro
0
130
Engineer Career Talk
lycorp_recruit_jp
0
190
複雑なState管理からの脱却
sansantech
PRO
1
150
生成AIが変えるデータ分析の全体像
ishikawa_satoru
0
170
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
310
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
880
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
390
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
190
Terraform Stacks入門 #HashiTalks
msato
0
360
Featured
See All Featured
Docker and Python
trallard
40
3.1k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Happy Clients
brianwarren
98
6.7k
Why Our Code Smells
bkeepers
PRO
334
57k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Code Review Best Practice
trishagee
64
17k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
What's in a price? How to price your products and services
michaelherold
243
12k
We Have a Design System, Now What?
morganepeng
50
7.2k
A Tale of Four Properties
chriscoyier
156
23k
Building Applications with DynamoDB
mza
90
6.1k
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. ͋Γ͕ͱ͏͍͟͝·ͨ͠