go gc algorithm 101

0db20c33cdd9bed3a7191d07a1c51c14?s=47 taxio
October 28, 2019

go gc algorithm 101

Go Conference 2019 Autumn

0db20c33cdd9bed3a7191d07a1c51c14?s=128

taxio

October 28, 2019
Tweet

Transcript

  1. 1.

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

    Autumn Oct 28, 2019 - Takuma Shiotsu(@taxio_tech)
  2. 7.

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

    ߏ੒͢Δཧ࿦ͱ࣮૷ʯ ‣ தଜ੒༸ FUD ʮΨϕʔδίϨΫγϣϯͷΞϧΰϦζϜͱ࣮૷ʯ w ॻ੶΍ϒϩάΛެ։͍ͯͩͬͯ͘͠͞Δํʑɼ ͦͯ͠ԿΑΓ(PͷDPOUSJCVUPSͷํʑʹਂ͘ײँ͠·͢
  3. 8.

    ©2019 Wantedly, Inc. "HFOEB w ࿩͢͜ͱ ‣ ($ͷجૅతͳཧ࿦ ‣ (PͰ࠾༻͞Ε͍ͯΔ($ΞϧΰϦζϜͷભҠͱ಺༰

    w ࿩͞ͳ͍͜ͱ ‣ (P͕࠾༻͍ͯ͠ͳ͍ଞͷ($ΞϧΰϦζϜ ‣ ώʔϓߏ଄ɼ"MMPDBUJPO΍&TDBQFղੳͷ࿩
  4. 9.

    ©2019 Wantedly, Inc. "HFOEB w ࠓ೔ͷηογϣϯͷྲྀΕ ‣ ($ͷجૅͷઆ໌ ‣ (Pͱ.BSL4XFFQ($

    ‣ (Pͱ$PODVSSFOU.BSL4XFFQ($ w ཧ࿦࣮૷ཧ࿦࣮૷ͷॱͰઆ໌͍͖ͯ͠·͢
  5. 12.
  6. 14.

    ©2019 Wantedly, Inc. ($ͷجૅ༻ޠ w ΦϒδΣΫτ ‣ ώʔϓྖҬ͔Β֬อ͢Δ σʔλߏ଄ͷ୯Ґ ‣

    ϔομΦϒδΣΫτͷϝλ৘ใ ‣ ϑΟʔϧυ஋΍ଞͷΦϒδΣΫτͷࢀর w ϛϡʔςʔλ ‣ ΦϒδΣΫτͷੜ੒ "MMPDBUJPO ΍ ߋ৽Λߦ͏ )FBEFS 'JFMET
  7. 15.

    ©2019 Wantedly, Inc. ($ͷجૅ༻ޠ w 3PPU ‣ ΦϒδΣΫτͷࢀরؔ܎Λ௥͏ͨΊͷ࢝఺ ‣ TUBDL΍TUBUJDྖҬʹอ࣋͞ΕΔม਺ͳͲ

    ‣ 3PPUʹଘࡏ͢ΔΦϒδΣΫτΛ3PPUΦϒδΣΫτͱݴ͏ w ࢮΜͰ͍ΔΦϒδΣΫτ ‣ 3PPU͔ΒḷΕͳ͍ΦϒδΣΫτ͸΋͏࢖ΘΕͳ͍͸ͣ  ͜ΕΛճऩ͍ͨ͠ %FBE 3PPU
  8. 16.

    ©2019 Wantedly, Inc. ͭ·Γ w ($ΞϧΰϦζϜͱ͍͏ͷ͸ɼ ‣ ࢮΜͰ͍Δੜ͖͍ͯΔΦϒδΣΫτΛͲ͏ݟ෼͚ͯɼ Ͳ͏ղ์͍ͯ͘͠ͷ͔ ‣

    ಈ͖ଓ͚ΔϛϡʔςʔλͱͲ͏͍͏࿈ܞΛऔΔͷ͔ w ධՁ࣠ ‣ -BUFODZϛϡʔςʔλͷ ࠷େ ఀࢭ࣌ؒ ‣ 5ISPVHIQVU୯Ґ࣌ؒ͋ͨΓͷώʔϓαΠζॲཧೳྗ ‣ ଞʹ΋ώʔϓྖҬͷঢ়ଶʹ͍͔ؔͯͭ͘͠
  9. 18.

    ©2019 Wantedly, Inc. .BSL4XFFQ($ w ೥ʹൃද͞Εͨ࠷ॳͷ($ΞϧΰϦζϜ ‣ +PIO.D$BSUIZ 3FDVSTJWFGVODUJPOTPGTZNCPMJDFYQSFTTJPOTBOE UIFJSDPNQVUBUJPOCZNBDIJOF

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

    ©2019 Wantedly, Inc. 4XFFQϑΣʔζ w ࢮΜͰ͍ΔΦϒδΣΫτΛճऩ͢ΔϑΣʔζ w ώʔϓྖҬΛ୺͔Β୳ࡧ w .BSLͷ෇͍͍ͯͳ͍ΦϒδΣΫτΛճऩ

    ‣ ࣍ͷ"MMPDBUJPOʹ࢖͏ͨΊͷ४උ ‣ ྫ͑͹GSFFͳPCKFDUΛ؅ཧ͓ͯ͘͠Ϧετʹ௥Ճ ✔ ✔ ✔ Heap
  11. 21.

    ©2019 Wantedly, Inc. .BSL4XFFQ($ w ϝϦοτ ‣ ୯७Ͱൺֱత࣮૷͕؆୯ w σϝϦοτ

    ‣ ϝϞϦͷஅยԽ ϑϥάϝϯςʔγϣϯ  ‣ ௿଎ͳ"MMPDBUJPO ‣ 458ͷӨڹͰMBUFODZ͕େ͖͍
  12. 22.

    ©2019 Wantedly, Inc. (Pͱ.BSL4XFFQ($ w (P·Ͱओʹ͜ͷΞϧΰϦζϜ w લճͷ($ͰNBSLͨ͠ੜଘΦϒδΣΫτͷ૯αΠζ  

    GOGC ͷϝϞϦ͕৽͘͠"MMPDBUF͞Εͨͱ͖ʹىಈ ‣ NBSLࡁΈ૯αΠζͷॳظ஋͸.# ‣ GOGC=offͷ৔߹($͸ىಈ͠ͳ͍ w ΋ͪΖΜ͜Ε͚ͩͩͱ஗͍ͷͰɼ ͍ͭ͘΋޻෉͕੝Γࠐ·Ε͍ͯΔ ‣ #JUNBQNBSLJOH 1BSBMMFMJNQM 5$.BMMPD FUD
  13. 27.

    ©2019 Wantedly, Inc. $PODVSSFOU.BSL4XFFQ($ w ϛϡʔςʔλͱ($Λฒߦʹಈ࡞ͤ͞Δ w ຬͨ͢΂͖ਖ਼౰ੑ ‣ গͳ͘ͱ΋3PPU͔Β౸ୡՄೳͳશͯͷPCKFDU͕

    ࣦΘΕͳ͍Α͏ʹ͢Δ ‣ ࠷ऴతʹ($Λ׬ྃ͢Δ w Ͳ͏΍ͬͯ͜ΕΒΛຬͨ͠ͳ͕Βฒߦ࣮ߦ͢Δͷ͔ʁ ‣ ৭NBSLJOH ‣ 8SJUFCBSSJFS
  14. 28.

    ©2019 Wantedly, Inc. ৭NBSLJOH w PCKFDUʹͭͷঢ়ଶΛఆٛ ศ্ٓɼ৭Ͱදݱ  ‣ നະ୳ࡧ

    NBSLແ͠  ‣ փ୳ࡧத NBSLࡁΈϦετʹೖΕ͓ͯ͘  ‣ ࠇ୳ࡧࡁΈ NBSLࡁΈϦετʹແ͍  w Ϧετ͔ΒΦϒδΣΫτͷࢀরΛऔΓग़͠ɼ ͦͷGJFMEΛ୳ࡧ͍ͯ͘͠ ‣ (PͰ͸RVFVFͱ࣮ͯ͠૷͞Ε͍ͯΔ Root
  15. 29.

    ©2019 Wantedly, Inc. 8SJUFCBSSJFS w ΦϒδΣΫτ͕໎ࢠʹͳΔ৚݅ ‣ ϛϡʔςʔλ͕നΦϒδΣΫτ΁ͷϙΠϯλΛ ࠇΦϒδΣΫτʹॻ͖ࠐΉ 

    શͯͷփ৭ΦϒδΣΫτ͔Βͷɼ ͦͷനΦϒδΣΫτ΁ͷܦ࿏͕ଘࡏ͠ͳ͍ w ͜ͷ৚͕݅ୡ੒͞Εͳ͍Α͏ʹ ϛϡʔςʔλͷΦϒδΣΫτૢ࡞ʹҰఆͷॲཧΛڬΉ ‣ ৭ʑͳख๏͕͋Δ ‣ (P͕࠾༻͍ͯ͠Δख๏͸ޙͰղઆ
  16. 30.

    ©2019 Wantedly, Inc. $PODVSSFOU.BSL4XFFQ($ w େ఍ɼҎԼͷϑΣʔζ͔Β੒Δ ‣ .BSLTFUVQ 458 

     3PPUΦϒδΣΫτΛશͯփ৭ʹృΔ  SVOUJNFͷ($ʹඞཁͳ͋Ε͜ΕͷॳظԽ ‣ $PODVSSFOUNBSL ‣ .BSLUFSNJOBUJPO 458   ඞཁͳ৔߹͸3PPUΛ࠶૸ࠪ ‣ $PODVSSFOUTXFFQ ‣ 4XFFQUFSNJOBUJPO 458
  17. 33.

    ©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
  18. 41.

    ©2019 Wantedly, Inc. (Pͷ$PODVSSFOU($ w ϑΣʔζ  4XFFQUFSNJOBUJPO  .BSLTFUVQ

     .BSL  .BSLUFSNJOBUJPO  4XFFQ w SFGHJUIVCDPNHPMBOHHPCMPCFBTSD SVOUJNFNHDHP
  19. 43.

    ©2019 Wantedly, Inc. .BSLTFUVQ w 458 w ॳظԽ ‣ gcphase_GCoff_GCmark

    ‣ 8SJUFCBSSJFS༗ޮԽ ‣ "TTJTU༗ޮԽ w 3PPUΦϒδΣΫτΛશͯփ৭ʹృΔ
  20. 46.

    ©2019 Wantedly, Inc. 4XFFQ w લॲཧ ‣ gcphase_GCmarktermination_GCoff ‣ 8SJUFCBSSJFSΛແޮԽ

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

    ©2019 Wantedly, Inc. ະདྷͷ(P($ w ($ΞϧΰϦζϜɼύϥμΠϜ͸ଞʹ·ͩ·ͩ͋Δ w ੈ୅ผ($Λಋೖ͍ͨ͠ͱ͍͏࿩͸͋Δ ‣ 3JDL

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