Upgrade to Pro — share decks privately, control downloads, hide ads and more …

go gc algorithm 101

taxio
October 28, 2019

go gc algorithm 101

Go Conference 2019 Autumn

taxio

October 28, 2019
Tweet

More Decks by taxio

Other Decks in Technology

Transcript

  1. ©2019 Wantedly, Inc. Go GC algorithm 101 Go Conference 2019

    Autumn Oct 28, 2019 - Takuma Shiotsu(@taxio_tech)
  2. ©2019 Wantedly, Inc. ँࣙ w ($ʹؔ͢Δ·ͱ·ͬͨ৘ใ͸ຊ౰ʹগͳ͍ ‣ 3JDIBSE+POFT FUD ʮΨϕʔδίϨΫγϣϯࣗಈϝϞϦ؅ཧΛ

    ߏ੒͢Δཧ࿦ͱ࣮૷ʯ ‣ தଜ੒༸ FUD ʮΨϕʔδίϨΫγϣϯͷΞϧΰϦζϜͱ࣮૷ʯ w ॻ੶΍ϒϩάΛެ։͍ͯͩͬͯ͘͠͞Δํʑɼ ͦͯ͠ԿΑΓ(PͷDPOUSJCVUPSͷํʑʹਂ͘ײँ͠·͢
  3. ©2019 Wantedly, Inc. "HFOEB w ࿩͢͜ͱ ‣ ($ͷجૅతͳཧ࿦ ‣ (PͰ࠾༻͞Ε͍ͯΔ($ΞϧΰϦζϜͷભҠͱ಺༰

    w ࿩͞ͳ͍͜ͱ ‣ (P͕࠾༻͍ͯ͠ͳ͍ଞͷ($ΞϧΰϦζϜ ‣ ώʔϓߏ଄ɼ"MMPDBUJPO΍&TDBQFղੳͷ࿩
  4. ©2019 Wantedly, Inc. "HFOEB w ࠓ೔ͷηογϣϯͷྲྀΕ ‣ ($ͷجૅͷઆ໌ ‣ (Pͱ.BSL4XFFQ($

    ‣ (Pͱ$PODVSSFOU.BSL4XFFQ($ w ཧ࿦࣮૷ཧ࿦࣮૷ͷॱͰઆ໌͍͖ͯ͠·͢
  5. ©2019 Wantedly, Inc. ($ͷجૅ༻ޠ w ΦϒδΣΫτ ‣ ώʔϓྖҬ͔Β֬อ͢Δ σʔλߏ଄ͷ୯Ґ ‣

    ϔομΦϒδΣΫτͷϝλ৘ใ ‣ ϑΟʔϧυ஋΍ଞͷΦϒδΣΫτͷࢀর w ϛϡʔςʔλ ‣ ΦϒδΣΫτͷੜ੒ "MMPDBUJPO ΍ ߋ৽Λߦ͏ )FBEFS 'JFMET
  6. ©2019 Wantedly, Inc. ($ͷجૅ༻ޠ w 3PPU ‣ ΦϒδΣΫτͷࢀরؔ܎Λ௥͏ͨΊͷ࢝఺ ‣ TUBDL΍TUBUJDྖҬʹอ࣋͞ΕΔม਺ͳͲ

    ‣ 3PPUʹଘࡏ͢ΔΦϒδΣΫτΛ3PPUΦϒδΣΫτͱݴ͏ w ࢮΜͰ͍ΔΦϒδΣΫτ ‣ 3PPU͔ΒḷΕͳ͍ΦϒδΣΫτ͸΋͏࢖ΘΕͳ͍͸ͣ  ͜ΕΛճऩ͍ͨ͠ %FBE 3PPU
  7. ©2019 Wantedly, Inc. ͭ·Γ w ($ΞϧΰϦζϜͱ͍͏ͷ͸ɼ ‣ ࢮΜͰ͍Δੜ͖͍ͯΔΦϒδΣΫτΛͲ͏ݟ෼͚ͯɼ Ͳ͏ղ์͍ͯ͘͠ͷ͔ ‣

    ಈ͖ଓ͚ΔϛϡʔςʔλͱͲ͏͍͏࿈ܞΛऔΔͷ͔ w ධՁ࣠ ‣ -BUFODZϛϡʔςʔλͷ ࠷େ ఀࢭ࣌ؒ ‣ 5ISPVHIQVU୯Ґ࣌ؒ͋ͨΓͷώʔϓαΠζॲཧೳྗ ‣ ଞʹ΋ώʔϓྖҬͷঢ়ଶʹ͍͔ؔͯͭ͘͠
  8. ©2019 Wantedly, Inc. .BSL4XFFQ($ w ೥ʹൃද͞Εͨ࠷ॳͷ($ΞϧΰϦζϜ ‣ +PIO.D$BSUIZ 3FDVSTJWFGVODUJPOTPGTZNCPMJDFYQSFTTJPOTBOE UIFJSDPNQVUBUJPOCZNBDIJOF

    $PNNVOJDBUJPOPGUIF"$. "QS w ͭͷϑΣʔζ͔Β੒Δ ‣ ੜ͖͍ͯΔΦϒδΣΫτΛ୳͢.BSLϑΣʔζ ‣ ࢮΜͰ͍ΔΦϒδΣΫτΛճऩ ղ์ ͢Δ4XFFQϑΣʔζ w ($͕ىಈ͔ͯ͠Βऴྃ͢Δ·Ͱɼϛϡʔςʔλ͸ಈ࡞͠ͳ͍ ‣ 458 4UPQ5IF8PSME  ‣ ͜Ε͕MBUFODZͷओͳཁҼ
  9. ©2019 Wantedly, Inc. 4XFFQϑΣʔζ w ࢮΜͰ͍ΔΦϒδΣΫτΛճऩ͢ΔϑΣʔζ w ώʔϓྖҬΛ୺͔Β୳ࡧ w .BSLͷ෇͍͍ͯͳ͍ΦϒδΣΫτΛճऩ

    ‣ ࣍ͷ"MMPDBUJPOʹ࢖͏ͨΊͷ४උ ‣ ྫ͑͹GSFFͳPCKFDUΛ؅ཧ͓ͯ͘͠Ϧετʹ௥Ճ ✔ ✔ ✔ Heap
  10. ©2019 Wantedly, Inc. .BSL4XFFQ($ w ϝϦοτ ‣ ୯७Ͱൺֱత࣮૷͕؆୯ w σϝϦοτ

    ‣ ϝϞϦͷஅยԽ ϑϥάϝϯςʔγϣϯ  ‣ ௿଎ͳ"MMPDBUJPO ‣ 458ͷӨڹͰMBUFODZ͕େ͖͍
  11. ©2019 Wantedly, Inc. (Pͱ.BSL4XFFQ($ w (P·Ͱओʹ͜ͷΞϧΰϦζϜ w લճͷ($ͰNBSLͨ͠ੜଘΦϒδΣΫτͷ૯αΠζ  

    GOGC ͷϝϞϦ͕৽͘͠"MMPDBUF͞Εͨͱ͖ʹىಈ ‣ NBSLࡁΈ૯αΠζͷॳظ஋͸.# ‣ GOGC=offͷ৔߹($͸ىಈ͠ͳ͍ w ΋ͪΖΜ͜Ε͚ͩͩͱ஗͍ͷͰɼ ͍ͭ͘΋޻෉͕੝Γࠐ·Ε͍ͯΔ ‣ #JUNBQNBSLJOH 1BSBMMFMJNQM 5$.BMMPD FUD
  12. ©2019 Wantedly, Inc. $PODVSSFOU.BSL4XFFQ($ w ϛϡʔςʔλͱ($Λฒߦʹಈ࡞ͤ͞Δ w ຬͨ͢΂͖ਖ਼౰ੑ ‣ গͳ͘ͱ΋3PPU͔Β౸ୡՄೳͳશͯͷPCKFDU͕

    ࣦΘΕͳ͍Α͏ʹ͢Δ ‣ ࠷ऴతʹ($Λ׬ྃ͢Δ w Ͳ͏΍ͬͯ͜ΕΒΛຬͨ͠ͳ͕Βฒߦ࣮ߦ͢Δͷ͔ʁ ‣ ৭NBSLJOH ‣ 8SJUFCBSSJFS
  13. ©2019 Wantedly, Inc. ৭NBSLJOH w PCKFDUʹͭͷঢ়ଶΛఆٛ ศ্ٓɼ৭Ͱදݱ  ‣ നະ୳ࡧ

    NBSLແ͠  ‣ փ୳ࡧத NBSLࡁΈϦετʹೖΕ͓ͯ͘  ‣ ࠇ୳ࡧࡁΈ NBSLࡁΈϦετʹແ͍  w Ϧετ͔ΒΦϒδΣΫτͷࢀরΛऔΓग़͠ɼ ͦͷGJFMEΛ୳ࡧ͍ͯ͘͠ ‣ (PͰ͸RVFVFͱ࣮ͯ͠૷͞Ε͍ͯΔ Root
  14. ©2019 Wantedly, Inc. 8SJUFCBSSJFS w ΦϒδΣΫτ͕໎ࢠʹͳΔ৚݅ ‣ ϛϡʔςʔλ͕നΦϒδΣΫτ΁ͷϙΠϯλΛ ࠇΦϒδΣΫτʹॻ͖ࠐΉ 

    શͯͷփ৭ΦϒδΣΫτ͔Βͷɼ ͦͷനΦϒδΣΫτ΁ͷܦ࿏͕ଘࡏ͠ͳ͍ w ͜ͷ৚͕݅ୡ੒͞Εͳ͍Α͏ʹ ϛϡʔςʔλͷΦϒδΣΫτૢ࡞ʹҰఆͷॲཧΛڬΉ ‣ ৭ʑͳख๏͕͋Δ ‣ (P͕࠾༻͍ͯ͠Δख๏͸ޙͰղઆ
  15. ©2019 Wantedly, Inc. $PODVSSFOU.BSL4XFFQ($ w େ఍ɼҎԼͷϑΣʔζ͔Β੒Δ ‣ .BSLTFUVQ 458 

     3PPUΦϒδΣΫτΛશͯփ৭ʹృΔ  SVOUJNFͷ($ʹඞཁͳ͋Ε͜ΕͷॳظԽ ‣ $PODVSSFOUNBSL ‣ .BSLUFSNJOBUJPO 458   ඞཁͳ৔߹͸3PPUΛ࠶૸ࠪ ‣ $PODVSSFOUTXFFQ ‣ 4XFFQUFSNJOBUJPO 458
  16. ©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
  17. ©2019 Wantedly, Inc. (Pͷ$PODVSSFOU($ w ϑΣʔζ  4XFFQUFSNJOBUJPO  .BSLTFUVQ

     .BSL  .BSLUFSNJOBUJPO  4XFFQ w SFGHJUIVCDPNHPMBOHHPCMPCFBTSD SVOUJNFNHDHP
  18. ©2019 Wantedly, Inc. .BSLTFUVQ w 458 w ॳظԽ ‣ gcphase_GCoff_GCmark

    ‣ 8SJUFCBSSJFS༗ޮԽ ‣ "TTJTU༗ޮԽ w 3PPUΦϒδΣΫτΛશͯփ৭ʹృΔ
  19. ©2019 Wantedly, Inc. 4XFFQ w લॲཧ ‣ gcphase_GCmarktermination_GCoff ‣ 8SJUFCBSSJFSΛແޮԽ

    w (P͸5$.BMMPDΛϕʔεͱͨ͠"MMPDBUJPOػߏ ‣ ίϨΫλ͕·ͩݟ͍ͯͳ͍ྖҬʹΦϒδΣΫτΛ֬อ͠ͳ͍Α ͏ʹɼ"MMPDBUJPO͢ΔલʹͦͷαΠζͷQBHFͷTXFFQॲཧΛ ਐΊ͓ͯ͘ ɾɾɾ ͜͜·ͰͷྖҬͳΒ
 നΦϒδΣΫτΛ֬อͯ͠΋େৎ෉ Heap (Page)
  20. ©2019 Wantedly, Inc. ະདྷͷ(P($ w ($ΞϧΰϦζϜɼύϥμΠϜ͸ଞʹ·ͩ·ͩ͋Δ w ੈ୅ผ($Λಋೖ͍ͨ͠ͱ͍͏࿩͸͋Δ ‣ 3JDL

    IUUQTCMPHHPMBOHPSHJTNNLFZOPUF *4.. ‣ ϨΠςϯγ͸Լ͕Δ͕8SJUFCBSSJFSʹΑͬͯɼ εϧʔϓοτ͕Լ͕ΔՄೳੑ͕͋Δ w ۩ମతͳٞ࿦͸·ͩݟ౰ͨΒͳ͍ ݟ͚ͭͯͳ͍ ͕ɼ (PͳͲͰͲ͏มΘָ͍͔͕ͬͯ͘͠Έ