Slide 1

Slide 1 text

©2019 Wantedly, Inc. Go GC algorithm 101 Go Conference 2019 Autumn Oct 28, 2019 - Takuma Shiotsu(@taxio_tech)

Slide 2

Slide 2 text

©2019 Wantedly, Inc. ࣗݾ঺հ ‣ Wantedly. Inc. 20ଔ಺ఆऀ ‣ ژ౎޻ܳણҡେֶେֶӃ M2 - ιϑτ΢ΣΞ޻ֶݚڀࣨ 5BLVNB4IJPUTV !UBYJP@UFDI

Slide 3

Slide 3 text

©2019 Wantedly, Inc. ✋($Λগ͠Ͱ΋஌͍ͬͯΔਓ✋

Slide 4

Slide 4 text

©2019 Wantedly, Inc. ✋ฉ͍ͨ͜ͱ΋ͳ͍ͱ͍͏ਓ✋

Slide 5

Slide 5 text

©2019 Wantedly, Inc. ✋࣮૷ͨ͜͠ͱ͕͋Δਓ✋

Slide 6

Slide 6 text

©2019 Wantedly, Inc. ຊηογϣϯͷ໨ඪ w ($ͱ͸Կ͔Λ஌Δ w ϓϩϑΝΠϧ݁ՌΛோΊ͍ͯΔͱ͖ʹͳΜͱͳ͘ SVOUJNFͷ($ϑΣʔζΛײ͡औΕΔΑ͏ʹͳΔ w 3FMFBTF/PUFͷ3VOUJNFͷ߲໨Λ ϫΫϫΫ͠ͳ͕ΒோΊΔ͖͔͚ͬΛ࣋ͭ

Slide 7

Slide 7 text

©2019 Wantedly, Inc. ँࣙ w ($ʹؔ͢Δ·ͱ·ͬͨ৘ใ͸ຊ౰ʹগͳ͍ ‣ 3JDIBSE+POFT FUD ʮΨϕʔδίϨΫγϣϯࣗಈϝϞϦ؅ཧΛ ߏ੒͢Δཧ࿦ͱ࣮૷ʯ ‣ தଜ੒༸ FUD ʮΨϕʔδίϨΫγϣϯͷΞϧΰϦζϜͱ࣮૷ʯ w ॻ੶΍ϒϩάΛެ։͍ͯͩͬͯ͘͠͞Δํʑɼ ͦͯ͠ԿΑΓ(PͷDPOUSJCVUPSͷํʑʹਂ͘ײँ͠·͢

Slide 8

Slide 8 text

©2019 Wantedly, Inc. "HFOEB w ࿩͢͜ͱ ‣ ($ͷجૅతͳཧ࿦ ‣ (PͰ࠾༻͞Ε͍ͯΔ($ΞϧΰϦζϜͷભҠͱ಺༰ w ࿩͞ͳ͍͜ͱ ‣ (P͕࠾༻͍ͯ͠ͳ͍ଞͷ($ΞϧΰϦζϜ ‣ ώʔϓߏ଄ɼ"MMPDBUJPO΍&TDBQFղੳͷ࿩

Slide 9

Slide 9 text

©2019 Wantedly, Inc. "HFOEB w ࠓ೔ͷηογϣϯͷྲྀΕ ‣ ($ͷجૅͷઆ໌ ‣ (Pͱ.BSL4XFFQ($ ‣ (Pͱ$PODVSSFOU.BSL4XFFQ($ w ཧ࿦࣮૷ཧ࿦࣮૷ͷॱͰઆ໌͍͖ͯ͠·͢

Slide 10

Slide 10 text

©2019 Wantedly, Inc. *OUSPEVDUJPO

Slide 11

Slide 11 text

©2019 Wantedly, Inc. ($ͱ͸ʁ w (BSCBHF$PMMFDUJPO w ώʔϓྖҬʹ֬อ͞Εͨɼ ΋͏࢖ΘΕͳ͍Ͱ͋Ζ͏ϝϞϦΛղ์͢Δ w (PͰ͸3VOUJNFʹ౥ࡌ͞Ε͍ͯΔ

Slide 12

Slide 12 text

©2019 Wantedly, Inc. (PͰ͸ w ҰఆͷλΠϛϯάͰ3VOUJNF͕($Λىಈ w runtime.GC()Ͱ΋ىಈՄೳ w ($ʹӨڹΛ༩͑Δ؀ڥม਺ ‣ GOGCɼGODEBUGʹ৭ʑ ‣ IUUQTRJJUBDPNNBUUOJUFNTFDGG

Slide 13

Slide 13 text

©2019 Wantedly, Inc. ($ͷجૅ༻ޠ

Slide 14

Slide 14 text

©2019 Wantedly, Inc. ($ͷجૅ༻ޠ w ΦϒδΣΫτ ‣ ώʔϓྖҬ͔Β֬อ͢Δ σʔλߏ଄ͷ୯Ґ ‣ ϔομΦϒδΣΫτͷϝλ৘ใ ‣ ϑΟʔϧυ஋΍ଞͷΦϒδΣΫτͷࢀর w ϛϡʔςʔλ ‣ ΦϒδΣΫτͷੜ੒ "MMPDBUJPO ΍ ߋ৽Λߦ͏ )FBEFS 'JFMET

Slide 15

Slide 15 text

©2019 Wantedly, Inc. ($ͷجૅ༻ޠ w 3PPU ‣ ΦϒδΣΫτͷࢀরؔ܎Λ௥͏ͨΊͷ࢝఺ ‣ TUBDL΍TUBUJDྖҬʹอ࣋͞ΕΔม਺ͳͲ ‣ 3PPUʹଘࡏ͢ΔΦϒδΣΫτΛ3PPUΦϒδΣΫτͱݴ͏ w ࢮΜͰ͍ΔΦϒδΣΫτ ‣ 3PPU͔ΒḷΕͳ͍ΦϒδΣΫτ͸΋͏࢖ΘΕͳ͍͸ͣ ͜ΕΛճऩ͍ͨ͠ %FBE 3PPU

Slide 16

Slide 16 text

©2019 Wantedly, Inc. ͭ·Γ w ($ΞϧΰϦζϜͱ͍͏ͷ͸ɼ ‣ ࢮΜͰ͍Δੜ͖͍ͯΔΦϒδΣΫτΛͲ͏ݟ෼͚ͯɼ Ͳ͏ղ์͍ͯ͘͠ͷ͔ ‣ ಈ͖ଓ͚ΔϛϡʔςʔλͱͲ͏͍͏࿈ܞΛऔΔͷ͔ w ධՁ࣠ ‣ -BUFODZϛϡʔςʔλͷ ࠷େ ఀࢭ࣌ؒ ‣ 5ISPVHIQVU୯Ґ࣌ؒ͋ͨΓͷώʔϓαΠζॲཧೳྗ ‣ ଞʹ΋ώʔϓྖҬͷঢ়ଶʹ͍͔ؔͯͭ͘͠

Slide 17

Slide 17 text

©2019 Wantedly, Inc. ۩ମతͳ($ΞϧΰϦζϜ

Slide 18

Slide 18 text

©2019 Wantedly, Inc. .BSL4XFFQ($ w ೥ʹൃද͞Εͨ࠷ॳͷ($ΞϧΰϦζϜ ‣ +PIO.D$BSUIZ 3FDVSTJWFGVODUJPOTPGTZNCPMJDFYQSFTTJPOTBOE UIFJSDPNQVUBUJPOCZNBDIJOF $PNNVOJDBUJPOPGUIF"$. "QS w ͭͷϑΣʔζ͔Β੒Δ ‣ ੜ͖͍ͯΔΦϒδΣΫτΛ୳͢.BSLϑΣʔζ ‣ ࢮΜͰ͍ΔΦϒδΣΫτΛճऩ ղ์ ͢Δ4XFFQϑΣʔζ w ($͕ىಈ͔ͯ͠Βऴྃ͢Δ·Ͱɼϛϡʔςʔλ͸ಈ࡞͠ͳ͍ ‣ 458 4UPQ5IF8PSME ‣ ͜Ε͕MBUFODZͷओͳཁҼ

Slide 19

Slide 19 text

©2019 Wantedly, Inc. .BSLϑΣʔζ w ੜ͖͍ͯΔΦϒδΣΫτΛݟ͚ͭΔϑΣʔζ w 3PPU͔Β୳ࡧ͍͖ͯ͠ɼ ݟ͚ͭͨΦϒδΣΫτͷϔομʹ.BSLΛ෇͚͍ͯ͘ ✔ ✔ ✔ Root

Slide 20

Slide 20 text

©2019 Wantedly, Inc. 4XFFQϑΣʔζ w ࢮΜͰ͍ΔΦϒδΣΫτΛճऩ͢ΔϑΣʔζ w ώʔϓྖҬΛ୺͔Β୳ࡧ w .BSLͷ෇͍͍ͯͳ͍ΦϒδΣΫτΛճऩ ‣ ࣍ͷ"MMPDBUJPOʹ࢖͏ͨΊͷ४උ ‣ ྫ͑͹GSFFͳPCKFDUΛ؅ཧ͓ͯ͘͠Ϧετʹ௥Ճ ✔ ✔ ✔ Heap

Slide 21

Slide 21 text

©2019 Wantedly, Inc. .BSL4XFFQ($ w ϝϦοτ ‣ ୯७Ͱൺֱత࣮૷͕؆୯ w σϝϦοτ ‣ ϝϞϦͷஅยԽ ϑϥάϝϯςʔγϣϯ ‣ ௿଎ͳ"MMPDBUJPO ‣ 458ͷӨڹͰMBUFODZ͕େ͖͍

Slide 22

Slide 22 text

©2019 Wantedly, Inc. (Pͱ.BSL4XFFQ($ w (P·Ͱओʹ͜ͷΞϧΰϦζϜ w લճͷ($ͰNBSLͨ͠ੜଘΦϒδΣΫτͷ૯αΠζ GOGC ͷϝϞϦ͕৽͘͠"MMPDBUF͞Εͨͱ͖ʹىಈ ‣ NBSLࡁΈ૯αΠζͷॳظ஋͸.# ‣ GOGC=offͷ৔߹($͸ىಈ͠ͳ͍ w ΋ͪΖΜ͜Ε͚ͩͩͱ஗͍ͷͰɼ ͍ͭ͘΋޻෉͕੝Γࠐ·Ε͍ͯΔ ‣ #JUNBQNBSLJOH 1BSBMMFMJNQM 5$.BMMPD FUD

Slide 23

Slide 23 text

©2019 Wantedly, Inc. #JUNBQNBSLJOH w ΦϒδΣΫτͷϔομʹ.BSLΛ෇͚ΔͷͰ͸ͳ͘ɼ ผͷྖҬʹ·ͱΊ͓ͯ͘ ‣ 4XFFQ࣌ͷ૸͕ࠪ଎͘ͳΔ ‣ .BSLϑϥάΛ໭͢ͷָ͕ ‣ $PQZPO8SJUFͱͷ૬ੑ͕͍͍

Slide 24

Slide 24 text

©2019 Wantedly, Inc. ͔͠͠458ͷӨڹͰ MBUFODZ͕େ͖͍

Slide 25

Slide 25 text

©2019 Wantedly, Inc. ͦ΋ͦ΋ͳͥ458͕ඞཁʁ w ($தʹϛϡʔςʔλ͕ΦϒδΣΫτͷࢀরߏ଄Λม͑ͯ ͠·͏ͱɼ੔߹ੑΛอূͰ͖ͳ͍ ྫ͑͹...

Slide 26

Slide 26 text

©2019 Wantedly, Inc. $PODVSSFOU .BSL4XFFQ($

Slide 27

Slide 27 text

©2019 Wantedly, Inc. $PODVSSFOU.BSL4XFFQ($ w ϛϡʔςʔλͱ($Λฒߦʹಈ࡞ͤ͞Δ w ຬͨ͢΂͖ਖ਼౰ੑ ‣ গͳ͘ͱ΋3PPU͔Β౸ୡՄೳͳશͯͷPCKFDU͕ ࣦΘΕͳ͍Α͏ʹ͢Δ ‣ ࠷ऴతʹ($Λ׬ྃ͢Δ w Ͳ͏΍ͬͯ͜ΕΒΛຬͨ͠ͳ͕Βฒߦ࣮ߦ͢Δͷ͔ʁ ‣ ৭NBSLJOH ‣ 8SJUFCBSSJFS

Slide 28

Slide 28 text

©2019 Wantedly, Inc. ৭NBSLJOH w PCKFDUʹͭͷঢ়ଶΛఆٛ ศ্ٓɼ৭Ͱදݱ ‣ നະ୳ࡧ NBSLແ͠ ‣ փ୳ࡧத NBSLࡁΈϦετʹೖΕ͓ͯ͘ ‣ ࠇ୳ࡧࡁΈ NBSLࡁΈϦετʹແ͍ w Ϧετ͔ΒΦϒδΣΫτͷࢀরΛऔΓग़͠ɼ ͦͷGJFMEΛ୳ࡧ͍ͯ͘͠ ‣ (PͰ͸RVFVFͱ࣮ͯ͠૷͞Ε͍ͯΔ Root

Slide 29

Slide 29 text

©2019 Wantedly, Inc. 8SJUFCBSSJFS w ΦϒδΣΫτ͕໎ࢠʹͳΔ৚݅ ‣ ϛϡʔςʔλ͕നΦϒδΣΫτ΁ͷϙΠϯλΛ ࠇΦϒδΣΫτʹॻ͖ࠐΉ શͯͷփ৭ΦϒδΣΫτ͔Βͷɼ ͦͷനΦϒδΣΫτ΁ͷܦ࿏͕ଘࡏ͠ͳ͍ w ͜ͷ৚͕݅ୡ੒͞Εͳ͍Α͏ʹ ϛϡʔςʔλͷΦϒδΣΫτૢ࡞ʹҰఆͷॲཧΛڬΉ ‣ ৭ʑͳख๏͕͋Δ ‣ (P͕࠾༻͍ͯ͠Δख๏͸ޙͰղઆ

Slide 30

Slide 30 text

©2019 Wantedly, Inc. $PODVSSFOU.BSL4XFFQ($ w େ఍ɼҎԼͷϑΣʔζ͔Β੒Δ ‣ .BSLTFUVQ 458 3PPUΦϒδΣΫτΛશͯփ৭ʹృΔ SVOUJNFͷ($ʹඞཁͳ͋Ε͜ΕͷॳظԽ ‣ $PODVSSFOUNBSL ‣ .BSLUFSNJOBUJPO 458 ඞཁͳ৔߹͸3PPUΛ࠶૸ࠪ ‣ $PODVSSFOUTXFFQ ‣ 4XFFQUFSNJOBUJPO 458

Slide 31

Slide 31 text

©2019 Wantedly, Inc. $PODVSSFOU.BSL4XFFQ($ w ϝϦοτ ‣ 458࡟ݮʹΑͬͯMBUFODZ͕ݮΔ w σϝϦοτ ‣ 8SJUFCBSSJFSʹΑͬͯεϧʔϓοτ͕Լ͕Δ

Slide 32

Slide 32 text

©2019 Wantedly, Inc. (PͰͷ࣮૷

Slide 33

Slide 33 text

©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

Slide 34

Slide 34 text

©2019 Wantedly, Inc. $PODVSSFOU($ಋೖ݁Ռ w MBUFODZ͕େ෯ʹݮͬͨ 'SPN3JDL)VETPO IUUQTUBMLTHPMBOHPSHHPHDQEG Q (PQIFS$PO%FOWFS +VMZ

Slide 35

Slide 35 text

©2019 Wantedly, Inc. (Pͷ8SJUFCBSSJFS w "MMPDBUJPO࣌ ‣ ৽֬͘͠อ͞ΕͨΦϒδΣΫτΛ௚ͪʹࠇʹృΔ Root ৽ΦϒδΣΫτ

Slide 36

Slide 36 text

©2019 Wantedly, Inc. (Pͷ8SJUFCBSSJFS w "MMPDBUJPO࣌ ‣ ৽֬͘͠อ͞ΕͨΦϒδΣΫτΛ௚ͪʹࠇʹృΔ Root ৽ΦϒδΣΫτ

Slide 37

Slide 37 text

©2019 Wantedly, Inc. (Pͷ8SJUFCBSSJFS w ΦϒδΣΫτͷࢀরؔ܎Λॻ͖׵͑ͨͱ͖ ‣ ࢀর͞Ε͍ͯͨ͞Ε͍ͯΔΦϒδΣΫτͷ྆ํΛփ৭ʹృΔ ‣ ͢ͰʹNBSL͞Ε͍ͯΔ փPSࠇ ৔߹͸Կ΋͠ͳ͍ Ͳ͔͔͜Βͷࢀর

Slide 38

Slide 38 text

©2019 Wantedly, Inc. (Pͷ8SJUFCBSSJFS w ΦϒδΣΫτͷࢀরؔ܎Λॻ͖׵͑ͨͱ͖ ‣ ࢀর͞Ε͍ͯͨ͞Ε͍ͯΔΦϒδΣΫτͷ྆ํΛփ৭ʹృΔ ‣ ͢ͰʹNBSL͞Ε͍ͯΔ փPSࠇ ৔߹͸Կ΋͠ͳ͍ Ͳ͔͔͜Βͷࢀর

Slide 39

Slide 39 text

©2019 Wantedly, Inc. (Pͷ8SJUFCBSSJFS w ΦϒδΣΫτͷࢀরؔ܎Λॻ͖׵͑ͨͱ͖ ‣ ࢀর͞Ε͍ͯͨ͞Ε͍ͯΔΦϒδΣΫτͷ྆ํΛփ৭ʹృΔ ‣ ͢ͰʹNBSL͞Ε͍ͯΔ փPSࠇ ৔߹͸Կ΋͠ͳ͍ Ͳ͔͔͜Βͷࢀর

Slide 40

Slide 40 text

©2019 Wantedly, Inc. (Pͷ8SJUFCBSSJFS w ($։࢝࣌ʹࢮΜͰ͍ΔΦϒδΣΫτΛճऩ͢Δ ‣ ($ऴྃ࣌ʹࢮΜͰ͍ΔΦϒδΣΫτ͕ଘࡏ͠ͳ͍อূ͸ແ͍ ‣ %JKLTUSBTUZMFͱ:VBTBTUZMFͷϋΠϒϦου w SFGHJUIVCDPNHPMBOHHPCMPCFBTSD SVOUJNFNCBSSJFSHP

Slide 41

Slide 41 text

©2019 Wantedly, Inc. (Pͷ$PODVSSFOU($ w ϑΣʔζ 4XFFQUFSNJOBUJPO .BSLTFUVQ .BSL .BSLUFSNJOBUJPO 4XFFQ w SFGHJUIVCDPNHPMBOHHPCMPCFBTSD SVOUJNFNHDHP

Slide 42

Slide 42 text

©2019 Wantedly, Inc. 4XFFQUFSNJOBUJPO w લճͷ4XFFQ͕ऴΘ͍ͬͯͳ͍৔߹͸ɼ 458Λͨ͠͏͑Ͱ4XFFQϑΣʔζΛऴΘΒͤΔ

Slide 43

Slide 43 text

©2019 Wantedly, Inc. .BSLTFUVQ w 458 w ॳظԽ ‣ gcphase_GCoff_GCmark ‣ 8SJUFCBSSJFS༗ޮԽ ‣ "TTJTU༗ޮԽ w 3PPUΦϒδΣΫτΛશͯփ৭ʹృΔ

Slide 44

Slide 44 text

©2019 Wantedly, Inc. .BSL w ($༻ͷHPSPVUJOF͕NBSLJOH͍ͯ͘͠ w .BSLJOHΑΓ"MMPDBUJPOͷ଎౓͕ૣ͍৔߹ɼ "TTJTU༻ͷHPSPVUJOF͕ىಈ͢Δ

Slide 45

Slide 45 text

©2019 Wantedly, Inc. .BSLUFSNJOBUJPO w 458 w NBSLϑΣʔζͷޙॲཧ ‣ gcphase_GCmark_GCmarktermination ‣ "TTJTUͳͲͷແޮԽ ‣ ࣍ͷ($ىಈ༻ͷώʔϓαΠζΛࢉग़

Slide 46

Slide 46 text

©2019 Wantedly, Inc. 4XFFQ w લॲཧ ‣ gcphase_GCmarktermination_GCoff ‣ 8SJUFCBSSJFSΛແޮԽ w (P͸5$.BMMPDΛϕʔεͱͨ͠"MMPDBUJPOػߏ ‣ ίϨΫλ͕·ͩݟ͍ͯͳ͍ྖҬʹΦϒδΣΫτΛ֬อ͠ͳ͍Α ͏ʹɼ"MMPDBUJPO͢ΔલʹͦͷαΠζͷQBHFͷTXFFQॲཧΛ ਐΊ͓ͯ͘ ɾɾɾ ͜͜·ͰͷྖҬͳΒ
 നΦϒδΣΫτΛ֬อͯ͠΋େৎ෉ Heap (Page)

Slide 47

Slide 47 text

©2019 Wantedly, Inc. Ͱ͸ͦͷઌ͸ʁ

Slide 48

Slide 48 text

©2019 Wantedly, Inc. ະདྷͷ(P($ w ($ΞϧΰϦζϜɼύϥμΠϜ͸ଞʹ·ͩ·ͩ͋Δ w ੈ୅ผ($Λಋೖ͍ͨ͠ͱ͍͏࿩͸͋Δ ‣ 3JDL IUUQTCMPHHPMBOHPSHJTNNLFZOPUF *4.. ‣ ϨΠςϯγ͸Լ͕Δ͕8SJUFCBSSJFSʹΑͬͯɼ εϧʔϓοτ͕Լ͕ΔՄೳੑ͕͋Δ w ۩ମతͳٞ࿦͸·ͩݟ౰ͨΒͳ͍ ݟ͚ͭͯͳ͍ ͕ɼ (PͳͲͰͲ͏มΘָ͍͔͕ͬͯ͘͠Έ

Slide 49

Slide 49 text

©2019 Wantedly, Inc. ·ͱΊ w $PODVSSFOU.BSL4XFFQ($Λ࠾༻͍ͯ͠Δ ‣ ($ىಈத͸($༻ͷHPSPVUJOF͕࡞ಈ͍ͯ͠Δ w ($ͷىಈλΠϛϯά͸؀ڥม਺GOGCͰௐ੔Մೳ w ($͸੒௕͠ଓ͚͍ͯΔ ‣ 3FMFBTFOPUF΍1SPQPTBMΛಡΉͷָ͕͠ΈͰ͢Ͷ

Slide 50

Slide 50 text

©2019 Wantedly, Inc. ͋Γ͕ͱ͏͍͟͝·ͨ͠