Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Inline?

Slide 5

Slide 5 text

Inline? • https://metacpan.org/pod/distribution/Inline/lib/Inline.pod • > Write Perl Subroutines in Other Programming Languages • ʮPerlͷؔ਺ΛଞͷݴޠͰॻ͍ͯ૊ΈࠐΜͰ࣮ߦ͢Δʯ • ͝ଘ஌ Ingy döt Net ޚେͷΞΠσΞ (2000೥)

Slide 6

Slide 6 text

Sample Code

Slide 7

Slide 7 text

Sample Code

Slide 8

Slide 8 text

Sample Code

Slide 9

Slide 9 text

Sample Code

Slide 10

Slide 10 text

Sample Code

Slide 11

Slide 11 text

Demo

Slide 12

Slide 12 text

How does it work?

Slide 13

Slide 13 text

How does it work? (Inline::C) • PerlͷίϯύΠϧϑΣΠζͰίϯύΠϧ͍ͯ͠Δ • _Inline/ σΟϨΫτϦʹ੒Ռ෺͕Ͱ͖Δ • md5ͷϑΟϯΨʔϓϦϯτ͕෇༩͞ΕΔ • ίϯύΠϧͯ͠Ͱ͖ͨόΠφϦΛμΠφϛοΫϦϯΫ

Slide 14

Slide 14 text

How does it work? (Inline::C)

Slide 15

Slide 15 text

How does it work? (Inline::Python) • Python.hΛXSϨΠϠͰ૊ΈࠐΜͰ͍Δ • Python.hΛ࢖ͬͯpythonίʔυΛevalͯ͠result objectʹ͢Δ • result objectΛperlίʔυʹม׵ • Python.hͰpythonίʔυ͔Β໊લۭؒ৘ใΛҾͬ͜ൈ͘ • Ҿͬ͜ൈ໊͍ͨલۭؒΛperlίʔυʹຒΊࠐΉ • Pythonͷݺͼग़͠෦෼Λϥοϓͯ͠perl͔Βݺͼग़͠Մೳʹ͢Δ • ͳͲ……

Slide 16

Slide 16 text

Why Inline?

Slide 17

Slide 17 text

Why Inline? • > The most obvious reason is performance. • > you may be able to remove a bottleneck in your Perl code by using another language

Slide 18

Slide 18 text

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ʹର͢Δݴٴͳ͠)

Slide 19

Slide 19 text

࣮ࡍͳͥInlineΛ? • Perlͷࢿ࢈͕͋ΓɼͲ͏ͯ͠΋PerlͰ΍Δඞཁ͕͋Γɼ
 ͦͯ͠PerlͰ͸ύϑΥʔϚϯε͕ग़ͳ͍෦෼Λิ͏ • ྫ͑͹਺஋ܭࢉ

Slide 20

Slide 20 text

Seriously?

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

Benchmark

Slide 24

Slide 24 text

Pros/Cons

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

Management Cost • ॲཧܥ͕2ͭ (͋Δ͍͸ͦΕҎ্) ʹͳΔίετ • ։ൃ؀ڥ੔උ͕͠ΜͲ͍ (όʔδϣϯϩοΫ౳) • ຊ൪؀ڥ੔උ΋͠ΜͲ͍ • όʔδϣϯϩοΫ • όʔδϣϯΞοϓ • Inline::X ͕࢖͏Ϟδϡʔϧͷόʔδϣϯ؅ཧ

Slide 28

Slide 28 text

ଈࢮʁ

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

GLUE language

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

PerlͷཱͪҐஔ • ϓϩάϥϛϯάݴޠPerlΑΓൈਮ • > ಉ࣌ʹଟ͘ͷϑΝΠϧ΍ϓϩηεͱ௨৴Ͱ͖Δͱ͍͏͜ͱ͕ɺ Perl͕ྑ͍άϧʔݴޠͰ͋Δཧ༝ (ͷͻͱͭ) ʹͳ͍ͬͯΔ • > ΤΫεςϯγϣϯϞδϡʔϧʹΑͬͯ಺෦ʹଞͷ΋ͷΛ૊Έࠐ ΊΔ͜ͱ

Slide 33

Slide 33 text

Glue => Inline • Inlineͱάϧʔݴޠͷࢥ૝͸ڧؔ͘࿈͍ͯ͠Δ • PerlΛ࣮ߦج൫ͱͯ͠ଞͷݴޠΛ૊ΈࠐΜͰಈ͔͢ • Perlͷࢿ࢈ͱଞͷݴޠͷࢿ࢈ͱΛγʔϜϨεʹ݁ͼ͚ͭΔ͜ͱ͕
 Ͱ͖Δ

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

Perl6ͷເ • use Inline::Perl5 • use Inline::Go • ͦͯ͠ଞݴޠ΁ͷม׵compiler • Java • Perl5 • JavaScript • ͳΜͰ΋ॻ͚Δ!!!

Slide 38

Slide 38 text

ॴײ

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

ॴײ • ʮPerlͷطଘࢿ࢈͕ࢧ഑తͰɼͲ͏ͯ͠΋࢖ΘͶ͹ͳΒͳ͍৔߹ʯͰ͸ͳ͍৔ ߹ • ಛʹ࢖͏ඞཁͳ͍ͱࢥ͏…… • ʮͲ͏ͯ͠΋Perlॻ͖ͨ͘ͳ͍ʂʂʯͱ͍͏γνϡΤʔγϣϯʹର͢Δ୤ग़ ϋονͰ͸ͳ͍ɹ • ʮPerlॻ͚ͳ͍͚Ͳϫϯνϟϯ……ʯͱ͔͸ͳ͍ • ਓΛڻ͔ͤΔͷ͕໨తͷ৔߹͸༗ޮ (ʁ) ͔΋͠Εͳ͍

Slide 42

Slide 42 text

ॴײ • > Maybe the best reason is "Because you want to!". Diversity keeps the world interesting. TMTOWTDI! • ࢓ࣄͩͱͦ͏΋ݴͬͯ͸͓ΕΜ……

Slide 43

Slide 43 text

·ͱΊ

Slide 44

Slide 44 text

·ͱΊ • PerlͷInlineϞδϡʔϧʹ͍ͭͯ͝঺հΛ͠·ͨ͠ • PerlͷInlineϞδϡʔϧͷpros/consʹ͍ͭͯઆ໌͠·ͨ͠ • ओʹੑೳ໘Ͱͷڧ͞Λૂ͑·͢ • άϧʔݴޠͷࠓੲʹ͍ͭͯ࿩͠·ͨ͠ • Inline͸Perl͕ݏʹͳͬͨਓͷͨΊͷ୤ग़ϋονͰ͸ͳ͍

Slide 45

Slide 45 text

མึͻΖ͍: ͜Μͳʹ͋ΔInlineϞδϡʔϧ

Slide 46

Slide 46 text

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

Slide 47

Slide 47 text

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

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

མึͻΖ͍: InlineϞδϡʔϧͷॻ͖ํ

Slide 50

Slide 50 text

InlineϞδϡʔϧͷॻ͖ํ • આ໌͢Δʹ͸͋·Γʹ͕࣌ؒͳ͍͜ͱ͕༧૝͞ΕΔͷͰͬ͘͟Γ • registerॻ͘ • buildॻ͘ • load/bindॻ͘ • ׬੒ʂʂʂ (͜͜ʹࢸΔ·Ͱʹͱͯͭ΋ͳ͍࿑ྗΛཁ͢Δ)

Slide 51

Slide 51 text

InlineϞδϡʔϧͷॻ͖ํ • Inline::CͱInline::Python͸Α͘Ͱ͖͍ͯΔͷͰࢀߟʹͳΔͱࢥ͍·͢

Slide 52

Slide 52 text

Q?