The World of Inline Module

672ee2598bea695496f11022a9a9c4c8?s=47 moznion
March 03, 2018

The World of Inline Module

YAPC::Okinawa 2018 Onnasonの資料です

672ee2598bea695496f11022a9a9c4c8?s=128

moznion

March 03, 2018
Tweet

Transcript

  1. The World of Inline Module YAPC::Okinawa 2018 Onnason @moznion

  2. None
  3. @moznion Software Engineer ࣾ಺ʹPerlϓϩδΣΫτ͸ ͋Γ·ͤΜ͕ ΍Δؾ࣍ୈͰ͸Ͱ͖·͢

  4. Inline?

  5. Inline? • https://metacpan.org/pod/distribution/Inline/lib/Inline.pod • > Write Perl Subroutines in Other

    Programming Languages • ʮPerlͷؔ਺ΛଞͷݴޠͰॻ͍ͯ૊ΈࠐΜͰ࣮ߦ͢Δʯ • ͝ଘ஌ Ingy döt Net ޚେͷΞΠσΞ (2000೥)
  6. Sample Code

  7. Sample Code

  8. Sample Code

  9. Sample Code

  10. Sample Code

  11. Demo

  12. How does it work?

  13. How does it work? (Inline::C) • PerlͷίϯύΠϧϑΣΠζͰίϯύΠϧ͍ͯ͠Δ • _Inline/ σΟϨΫτϦʹ੒Ռ෺͕Ͱ͖Δ

    • md5ͷϑΟϯΨʔϓϦϯτ͕෇༩͞ΕΔ • ίϯύΠϧͯ͠Ͱ͖ͨόΠφϦΛμΠφϛοΫϦϯΫ
  14. How does it work? (Inline::C)

  15. How does it work? (Inline::Python) • Python.hΛXSϨΠϠͰ૊ΈࠐΜͰ͍Δ • Python.hΛ࢖ͬͯpythonίʔυΛevalͯ͠result objectʹ͢Δ

    • result objectΛperlίʔυʹม׵ • Python.hͰpythonίʔυ͔Β໊લۭؒ৘ใΛҾͬ͜ൈ͘ • Ҿͬ͜ൈ໊͍ͨલۭؒΛperlίʔυʹຒΊࠐΉ • Pythonͷݺͼग़͠෦෼Λϥοϓͯ͠perl͔Βݺͼग़͠Մೳʹ͢Δ • ͳͲ……
  16. Why Inline?

  17. Why Inline? • > The most obvious reason is performance.

    • > you may be able to remove a bottleneck in your Perl code by using another language
  18. Why Inline? • > There are already two major facilities

    for extending Perl with C. They are XS and SWIG. • > There is a big fat learning curve involved with setting up and using the XS • (SWIGʹର͢Δݴٴͳ͠)
  19. ࣮ࡍͳͥInlineΛ? • Perlͷࢿ࢈͕͋ΓɼͲ͏ͯ͠΋PerlͰ΍Δඞཁ͕͋Γɼ
 ͦͯ͠PerlͰ͸ύϑΥʔϚϯε͕ग़ͳ͍෦෼Λิ͏ • ྫ͑͹਺஋ܭࢉ

  20. Seriously?

  21. Seriously? • (ঢ়گʹΑͬͯ͸) Ϛδ

  22. Benchmark • https://gist.github.com/moznion/83dfd5cccb6a8d59a7a7e9e101d64cf8

  23. Benchmark

  24. Pros/Cons

  25. Pros • طଘࢿ࢈Λ࢖্ͬͨͰ؆୯ʹυʔϐϯά͕Մೳ • ଞͷݴޠΛૉ௚ʹॻ͚ΔͷͰɼXSΑΓൺֱతͱ͖ͬͭ΍͍͢ [ཁग़య] • https://metacpan.org/pod/distribution/Inline-C/lib/Inline/C/Cookbook.pod • ΢ο

  26. Cons • ىಈ࣌ͷΦʔόϔου͕͋Δ • ؀ڥߏங͕େม • ଈࢮ͢ΔՄೳੑ͕͋Δ

  27. Management Cost • ॲཧܥ͕2ͭ (͋Δ͍͸ͦΕҎ্) ʹͳΔίετ • ։ൃ؀ڥ੔උ͕͠ΜͲ͍ (όʔδϣϯϩοΫ౳) •

    ຊ൪؀ڥ੔උ΋͠ΜͲ͍ • όʔδϣϯϩοΫ • όʔδϣϯΞοϓ • Inline::X ͕࢖͏Ϟδϡʔϧͷόʔδϣϯ؅ཧ
  28. ଈࢮʁ

  29. Mentality • ͦΕ͹͔Γ͸ͳΜͱ΋…… • ͞·͟·ͳঢ়گʹΑΔ (৘ใྔ͕ແ)

  30. GLUE language

  31. άϧʔݴޠ • ଞͷιϑτ΢ΣΞίϯϙʔωϯτͱ࿈ܞͤ͞ΔͨΊͷݴޠ • e.g. γΣϧεΫϦϓτ

  32. PerlͷཱͪҐஔ • ϓϩάϥϛϯάݴޠPerlΑΓൈਮ • > ಉ࣌ʹଟ͘ͷϑΝΠϧ΍ϓϩηεͱ௨৴Ͱ͖Δͱ͍͏͜ͱ͕ɺ Perl͕ྑ͍άϧʔݴޠͰ͋Δཧ༝ (ͷͻͱͭ) ʹͳ͍ͬͯΔ •

    > ΤΫεςϯγϣϯϞδϡʔϧʹΑͬͯ಺෦ʹଞͷ΋ͷΛ૊Έࠐ ΊΔ͜ͱ
  33. Glue => Inline • Inlineͱάϧʔݴޠͷࢥ૝͸ڧؔ͘࿈͍ͯ͠Δ • PerlΛ࣮ߦج൫ͱͯ͠ଞͷݴޠΛ૊ΈࠐΜͰಈ͔͢ • Perlͷࢿ࢈ͱଞͷݴޠͷࢿ࢈ͱΛγʔϜϨεʹ݁ͼ͚ͭΔ͜ͱ͕
 Ͱ͖Δ

  34. ͔͠͠άϧʔݴޠͬͯฉ͔ͳ͘ͳΓ·ͨ͠Ͷ • Over HTTPͷAPI callingͷൃୡ • ݴޠΑΓ΋ԼͷϨΠϠͷΠϯλʔϑΣʔε͕੔ͬͨͷͰɼͦ͜ ͰؤுΔඞཁ͕ബ͘ͳͬͨͱ͍͏ͷ͸͋Γͦ͏ • ͔ͭͯͷCORBA΍SOAP΍XMLRPCΑΓஅવʹ؀ڥ͸Α͘ͳͬͨ

  35. • ͱ͸ݴ͑Over HTTPͰAPIΛݺͼग़ͦ͏ͱ͢ΔͱϨΠςϯγ͕͋Δ • ͦͷϨΠςϯγ͕ແࢹͰ͖ͳ͘ͳΔλΠϛϯά͸ଘࡏ͢Δ • ͦͷ࣌ͷͨΊͷ୤ग़ϋονͱͯ͠Inline͸࢖͑Δ ͔͠͠άϧʔݴޠͬͯฉ͔ͳ͘ͳΓ·ͨ͠Ͷ

  36. ର͢ΔLLVMͷख๏ • ҃ΔݴޠΛ҃Δݴޠʹม׵͢Δͱ͍͏ख๏ • ໌Β͔ʹਖ਼͍͠ʂʂʂʂʂ • ͜Ε΋ʮάϧʔݴޠʯ͕ਰୀ͍ͯͬͨ͠ҰҼͰ͸ͳ͍͔

  37. Perl6ͷເ • use Inline::Perl5 • use Inline::Go • ͦͯ͠ଞݴޠ΁ͷม׵compiler •

    Java • Perl5 • JavaScript • ͳΜͰ΋ॻ͚Δ!!!
  38. ॴײ

  39. ॴײ • Perlͷطଘࢿ࢈͕ࢧ഑తͰɼͲ͏ͯ͠΋࢖ΘͶ͹ͳΒͳ͍৔߹͸
 બ୒ࢶͷҰͭʹͳΓ͑Δ • ʮશ෦ॻ͖௚ͧ͢ʂʂʂʯ͕Ͱ͖ͳ͍͜ͱ͸ੈͷதʹ͸ଟ͍ • ͦͯ͠ಘͯͯ͠ʮશ෦ॻ͖௚ͧ͢ʂʂʂʯ͸ϙγϟΓ͕ͪ • ΢ο

  40. ॴײ • ͓ͱͳ͘͠XSͰॻ͘ͱ͍͏ํ๏΋͋Δ • ͓ͦΒ͘ϝϯόʔ͕XSͷΤΩεύʔτͰ͋Δඞཁ͕͋Δ • ͦ͏Ͱͳ͍৔߹͸υΩϡϝϯτʹ͋ΔΑ͏ʹ։ൃʹ͕͔͔࣌ؒΔ • ͔ͦ͠͠͏ͳͬͯ͘ΔͱPerlͰॻ͍͍ͯΔͷ͔Կͳͷ͔Θ͔Βͳ͘
 ͳΔͧ……

  41. ॴײ • ʮPerlͷطଘࢿ࢈͕ࢧ഑తͰɼͲ͏ͯ͠΋࢖ΘͶ͹ͳΒͳ͍৔߹ʯͰ͸ͳ͍৔ ߹ • ಛʹ࢖͏ඞཁͳ͍ͱࢥ͏…… • ʮͲ͏ͯ͠΋Perlॻ͖ͨ͘ͳ͍ʂʂʯͱ͍͏γνϡΤʔγϣϯʹର͢Δ୤ग़ ϋονͰ͸ͳ͍ɹ •

    ʮPerlॻ͚ͳ͍͚Ͳϫϯνϟϯ……ʯͱ͔͸ͳ͍ • ਓΛڻ͔ͤΔͷ͕໨తͷ৔߹͸༗ޮ (ʁ) ͔΋͠Εͳ͍
  42. ॴײ • > Maybe the best reason is "Because you

    want to!". Diversity keeps the world interesting. TMTOWTDI! • ࢓ࣄͩͱͦ͏΋ݴͬͯ͸͓ΕΜ……
  43. ·ͱΊ

  44. ·ͱΊ • PerlͷInlineϞδϡʔϧʹ͍ͭͯ͝঺հΛ͠·ͨ͠ • PerlͷInlineϞδϡʔϧͷpros/consʹ͍ͭͯઆ໌͠·ͨ͠ • ओʹੑೳ໘Ͱͷڧ͞Λૂ͑·͢ • άϧʔݴޠͷࠓੲʹ͍ͭͯ࿩͠·ͨ͠ •

    Inline͸Perl͕ݏʹͳͬͨਓͷͨΊͷ୤ग़ϋονͰ͸ͳ͍
  45. མึͻΖ͍: ͜Μͳʹ͋ΔInlineϞδϡʔϧ

  46. ͜Μͳʹ͋ΔInlineϞδϡʔϧ

  47. ͜Μͳʹ͋ΔInlineϞδϡʔϧ

  48. ͜Μͳʹ͋ΔInlineϞδϡʔϧ • DAVIDO/Inline::CPP • RHOELZ/Inline::Lua • MIYAGAWA/Inline::Basic • RRS/Inline::Tcl •

    NEILW/Inline::ASM • etc...
  49. མึͻΖ͍: InlineϞδϡʔϧͷॻ͖ํ

  50. InlineϞδϡʔϧͷॻ͖ํ • આ໌͢Δʹ͸͋·Γʹ͕࣌ؒͳ͍͜ͱ͕༧૝͞ΕΔͷͰͬ͘͟Γ • registerॻ͘ • buildॻ͘ • load/bindॻ͘ •

    ׬੒ʂʂʂ (͜͜ʹࢸΔ·Ͱʹͱͯͭ΋ͳ͍࿑ྗΛཁ͢Δ)
  51. InlineϞδϡʔϧͷॻ͖ํ • Inline::CͱInline::Python͸Α͘Ͱ͖͍ͯΔͷͰࢀߟʹͳΔͱࢥ͍·͢

  52. Q?