Compare Benchmarks and Compiler Optimization In Go

Compare Benchmarks and Compiler Optimization In Go

Go(Un) Conference #6

4d78b749c315e21a956053dcbf0508a9?s=128

po3rin

May 27, 2019
Tweet

Transcript

  1. Compare Benchmarks and Compiler Optimization In Go Go Un Conference

    May 27, 2019 @ po3rin
  2. @po3rin Software Enginner @ Shiroyagi Corporation QBHF Golang / Python

    / Rust / Docker / AWS / Elasticsearch
  3. QBHF Introduction \

  4. QBHF 044ʹίϛοτΛࢼΈΔࡍʹɺʮͳͥ ͜ͷ࣮૷͕ྑ͍͔ʯΛূ໌͢Δҝʹ (Pʹ͓͚ΔϕϯνϚʔΫʹ͍ͭͯௐ΂ ͨͷͰͦΕΛൃද͠·͢ɻ Benchmark of Go Ὂ

  5. QBHF ɾϕϯνϚʔΫΛʮূ໌ʯʹ࢖͑ΔΑ͏ʹͳΔ ɾϕϯνϚʔΫ௥ٻ͔ΒίϯύΠϥ࠷దԽΛআ͘ Ὂ the porpose of this talk

  6. QBHF Review how to take a benchmark \

  7. QBHF Review how to take a benchmark Ὂ ֤ϕϯνϚʔΫؔ਺͸C/ճ൓෮ ͞Ε·͢ɻσϑΥϧτͰ͸C/͸

    ͔Β࢝·Γ·͕͢ɺϕϯνϚʔ Ϋػೳ͕ඵҎ಺ʹ׬ྃͨ͠৔߹ C/͕૿Ճͯ͠ϕϯνϚʔΫ͕࠶ ࣮ߦ͞Ε·͢ɻ
  8. QBHF Review how to take a benchmark Ὂ ݁ՌΛݟΔͱͱ͍͏TV⒏Y͕͍͍ͭͯ·͢ɻ͜Ε͸͜ͷςετΛ࣮ߦ͢ΔͨΊ ʹ࢖༻͞Εͨ(0."9130$4ͷ஋Ͱ͢ɻ͜ͷ਺͸σϑΥϧτͰىಈ࣌ʹ(Pϓϩ

    ηεʹݟ͑Δ$16ͷ਺ʹͳΓ·͢ɻ
  9. QBHF -cpu Ὂ (0."9130$4͸DQVϑϥάͰมߋͰ͖·͢ɻνʔϜؒͰϕϯνϚʔΫΛ࢖͍ճ ࣌͢͸$16ͷ਺͕ϕϯνϚʔΫʹӨڹΛ༩͑ͳ͍Α͏ʹ஫ҙ͕ඞཁͰ͢ɻ

  10. QBHF -benchtime Ὂ ൓෮ճ਺Λ૿΍͢ҝʹ CFODIUJNFϑϥάΛ࢖༻ ͯ͠ϕϯνϚʔΫ࣌ؒΛ ૿΍͢͜ͱ͕Ͱ͖·͢ɻ (P͔ΒCFODIUJNF ϑϥά͸൓෮ճ਺Λࢦఆ Ͱ͖·͢ɻ

  11. QBHF Benchmark cost avoidance Ὂ C3FTFU5JNFS ͰηοτΞοϓͰ ൃੜ͢ΔίετΛճආͰ͖·͢ɻ ϧʔϓͷ൓෮͝ͱʹίετ͕ߴ͍ ηοτΞοϓ͕͋Δ৔߹͸ɺ

    C4UPQ5JNFS ͓Αͼ C4UBSU5JNFS Λ࢖༻͠·͢ɻ
  12. QBHF Check allocations Ὂ Ξϩέʔγϣϯͷ਺ͱαΠζ͸ɺϕϯνϚʔΫͱڧ͘૬͍ؔͯ͠·͢ɻΞϩέʔ γϣϯͷ਺ΛϕϯνϚʔΫͰ֬ೝ͢Δ࣌͸CFODINFNΛ࢖͍·͢ɻ

  13. QBHF Benchmark stability \

  14. QBHF Benchmark stability Ὂ ਺ඦສ·ͨ͸਺ेԯճ΄Ͳ൓෮࣮ߦ͞ ΕΔϕϯνϚʔΫ͕OTdNTͷൣғ ͷͳΔ৔߹ɺϕϯνϚʔΫ਺͸೤ε έʔϦϯάɺϝϞϦہॴੑͳͲ༷ʑͳ ཁҼʹΑΓෆ҆ఆʹͳ͍ͬͯ·͢ɻ

  15. QBHF Benchmark stability Ὂ ͜ͷΑ͏ͳ৔߹͸DPVOUϑ ϥάΛ࢖༻ͯ͠ɺϕϯν ϚʔΫΛෳ਺ճ࣮ߦ͢Δ͜ ͱͰϕϯνϚʔΫͷ෼ࢄ΋ ؚΊͯ֬ೝ͢Δͷ͕ಘࡦͰ ͢ɻ

  16. QBHF Benchmark stability Ὂ ҰํͰϕϯνϚʔΫͷ҆ఆ౓ΛݟΔͷʹศརͳπʔϧ͕͋Γ· ͢ɻ3VTT$PYʹΑΔCFODITUBUͱ͍͏πʔϧΛ঺հ͠·͢ɻ

  17. QBHF Benchmark stability Ὂ CFODITUBU͸Ұ࿈ͷϕϯνϚʔΫ ςετΛ࣮ߦͯ͠ɺͦΕΒ͕ͲΕ ΄Ͳ҆ఆ͍ͯ͠Δ͔Λڭ͑ͯ͘Ε ·͢ɻ

  18. QBHF Comparing benchmarks \

  19. QBHF Comparing benchmarks Ὂ ϕϯνϚʔΫؒͷύϑΥʔϚϯεͷࠩΛ൑அ͢Δͷ͸໘౗Ͱ͕͢ɺ CFODITUBU͸͜ͷ໰୊΋ղܾ͠·͢ɻ

  20. QBHF ૣ଎'JC Λվྑ͍ͨ͠ͷͰ͕͢ɺίʔυΛվྑͨ͠ޙͰɺ ΋͏Ұ౓վྑલͷϕϯνϚʔΫΛऔΓ͍͕ͨ࣌ग़͖ͯͨΒ Ͳ͏͠·͠ΐ͏͔ɻ࣮͸HPUFTUʹ͸લճͷϕϯνϚʔΫ݁ ՌΛੜ੒ͨ͠όΠφϦΛอଘ͓ͯ͘͜͠ͱ͕Ͱ͖ΔػೳΛ ఏڙ͢ΔDϑϥοά͕ଘࡏ͠·͢ɻվྑલͷόΠφϦ໊ ͸UFTU͔ΒHPMEFOʹมߋ͢Δͷ͕௨ྫͷΑ͏Ͱ͢ɻ -c Ὂ

  21. QBHF ϕϯνϚʔΫΛൺֱ͢Δҝ ʹ࠶ؼݺͼग़͠Λ̍ͭݮΒ ͠·͢ɻ Reduce recursive calls Ὂ

  22. QBHF 'JC  Ͱ͸'JC  ͱൺ΂ͯͷվྑ͕֬ೝͰ͖·͢ɻιʔείʔυͷมߋ ޙʹͲͷ͘Β͍ͷվળ͕͋ͬͨͷ͔Λূ໌͢Δͷʹ༗༻Ͱ͢ɻ෼ࢄ͕େ͖͍ϕϯ νϚʔΫΛൺֱ͢Δͱ͖͸஫ҙɻ Comparing benchmarks

  23. QBHF O͸ɺ༗ޮͩͱݟͳ͞Εͨσʔλͷݸ਺Λද͠·͢ɻσʔλͷغ٫཰͕ˋΛ௒͑ Δͱൺֱ͢Δαϯϓϧ͕গͳ͗͢ΔՄೳੑ͕͋Γ·͢ɻ Q͕Λ௒͑Δ͜ͱ͸ϕϯνϚʔΫ͕౷ܭతʹ༗ҙͰ͸ͳ͍͜ͱΛҙຯ͠·͢ɻ Q஋ʹ͍ͭͯ͸Լه͕ৄ͍͠Ͱ͢ɻ ౷ܭֶతݕఆͷ1஋ɺ౷ܭֶతʹ༗ҙɺ༗ҙࠩɺ༗ҙਫ४ͱ͸Կ͔ʁ IUUQUPVLFJMJOLCBTJDTUBUJTUJDTQWBMVF@BOE@TJHOJpDBODF Comparing benchmarks Ὂ

  24. QBHF Watch out for compiler optimisations \

  25. QBHF ਐ਺Ͱදͨ͠ͱཱ͖͍ͬͯΔ Ϗοτͷ਺Λฦ͠·͢ɻ͜ͷؔ ਺ͷϕϯνϚʔΫΛͱΓ·͠ΐ ͏ɻ compiler optimisations Ὂ

  26. QBHF ͜ͷ݁Ռͷඵ͸֓ͶΫϩοΫप೾਺Ͱ͢ɻΑͬͯ͜ͷ஋͸͔ͳΓ͓͔͍͠Ͱ͢ɻ $16͸ΫϩοΫ৴߸ʹ߹Θͤͯಈ࡞͠·͢  QPQDOU͸Ϧʔϑؔ਺ ଞͷؔ਺͸ݺͼग़͠Λ͠ͳ͍ ʹͳ͍ͬͯ·͢ɻɻίϯύΠϥ͸͜ ͷؔ਺ΛΠϯϥΠϯల։Ͱ͖·͢ɻͦͯ͠QPQDOU͸ɺͲͷάϩʔόϧม਺ͷঢ়ଶʹ΋ Өڹ͠·ͤΜɻ͕ͨͬͯ͠ɺݺͼग़ࣗ͠ମ͕ഉআ͞Ε͍ͯ·͢ɻ compiler

    optimisations Ὂ
  27. QBHF ϕϯνϚʔΫΛػೳͤ͞ΔͨΊʹΠϯ ϥΠϯԽΛແޮʹ͢Δ͜ͱ͸ଞͷϕϯ νϚʔΫʹ΋Өڹ͕͋ΔͷͰ͓͢͢Ί ͠·ͤΜɻ্̎ͭ͸ίϯύΠϥ͕ϧʔ ϓຊମΛ࠷దԽͰ͖ͳ͍Α͏ʹ͢Δͨ Ίͷਪ঑ํ๏Ͱ͢ɻ compiler optimisations Ὂ

  28. QBHF JOMJOJOHͳͲͷίϯύΠϥ࠷దԽͷঢ়گΛ֬ೝ͢Δʹ͸HDqBHTΛ࢖͍·͢ɻ -gcflags Ὂ

  29. QBHF ͞ΒʹڧྗͳJOMJOJOH͕(P͔ΒೖͬͯΔ IUUQTEPDTHPPHMFDPNQSFTFOUBUJPOE8DCMQKQGF,X":'0NK18.@RN/RM2L/B-K1PFEJUTMJEFJEQ Mid Stack inlining Ὂ

  30. QBHF Conclusion \

  31. QBHF (Pʹ͓͚ΔϕϯνϚʔΫ͸؆୯ʹऔΕΔ͕ɺ࢖͍ํʹ͸஫ҙ͕ඞཁɻ ϕϯνϚʔΫͷ؀ڥͷఏࣔ౷Ұ ϕϯνϚʔΫͷ҆ఆੑͷ֬ೝ ͓͔͍͘͠Β͍଎͍࣌͸ϕϯνϚʔΫ࣌ͷίϯύΠϥ࠷దԽͷڍಈΛ֬ೝ Conclusion Ὂ

  32. QBHF Additional Talk \

  33. QBHF (P$POGFSFODF'VLVPLB Ͱ΋ొஃ͠·͢ʂ

  34. Benchmark and Compiler Optimization In Go Go Un Conference May

    27, 2019 @ po3rin