Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The World of Inline Module
Search
moznion
March 03, 2018
Technology
0
5.3k
The World of Inline Module
YAPC::Okinawa 2018 Onnasonの資料です
moznion
March 03, 2018
Tweet
Share
More Decks by moznion
See All by moznion
Develop to Survive - YAPC::Hakodate 2024 Keynote
moznion
9
13k
これはPerl? それともRuby? クイズ〜〜〜〜〜!!!- Perl or Ruby Quiz
moznion
3
2.3k
Perl 5 OOP機構30年史 - Perl 5's OOP Mechanism over the past 30 years
moznion
1
890
RuboCopのカスタムCopを書いてContributionしてみる - Contributing a Custom Cop to RuboCop: A Hands-on Experience
moznion
0
60
AWS上に構築する メンテ容易なElasticsearch System / Maintainable Elasticsearch system on AWS
moznion
2
3.9k
PROXY Protocol aware Proxy Server on Node.js
moznion
2
2.4k
Perl meets AWS Lambda
moznion
0
4.7k
ソフトウェア開発における 「設計」と「パフォーマンス」の相互作用 / Interaction Between Design and Performance on Software Development
moznion
12
6.9k
Javaカードの世界 / The world of Java Card
moznion
9
13k
Other Decks in Technology
See All in Technology
利きプロセススケジューラ
sat
PRO
5
2.7k
AWS⼊社という選択肢、⾒えていますか
iwamot
2
1.1k
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
140
BLADE: An Attempt to Automate Penetration Testing Using Autonomous AI Agents
bbrbbq
0
130
SREの組織類型に応じた リーダシップの考察
kenta_hi
PRO
1
640
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
340
データ活用促進のためのデータ分析基盤の進化
takumakouno
2
800
TypeScriptの次なる大進化なるか!? 条件型を返り値とする関数の型推論
uhyo
1
1.2k
인디 앱 개발자와 Flutter
tinyjin
0
150
Evangelismo técnico: ¿qué, cómo y por qué?
trishagee
0
320
Lambdaと地方とコミュニティ
miu_crescent
2
320
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
31
6.3k
Raft: Consensus for Rubyists
vanstee
136
6.6k
What's new in Ruby 2.0
geeforr
343
31k
Making Projects Easy
brettharned
115
5.9k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Producing Creativity
orderedlist
PRO
341
39k
BBQ
matthewcrist
85
9.3k
A Philosophy of Restraint
colly
203
16k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Transcript
The World of Inline Module YAPC::Okinawa 2018 Onnason @moznion
None
@moznion Software Engineer ࣾʹPerlϓϩδΣΫτ ͋Γ·ͤΜ͕ Δؾ࣍ୈͰͰ͖·͢
Inline?
Inline? • https://metacpan.org/pod/distribution/Inline/lib/Inline.pod • > Write Perl Subroutines in Other
Programming Languages • ʮPerlͷؔΛଞͷݴޠͰॻ͍ͯΈࠐΜͰ࣮ߦ͢Δʯ • ͝ଘ Ingy döt Net ޚେͷΞΠσΞ (2000)
Sample Code
Sample Code
Sample Code
Sample Code
Sample Code
Demo
How does it work?
How does it work? (Inline::C) • PerlͷίϯύΠϧϑΣΠζͰίϯύΠϧ͍ͯ͠Δ • _Inline/ σΟϨΫτϦʹՌ͕Ͱ͖Δ
• md5ͷϑΟϯΨʔϓϦϯτ͕༩͞ΕΔ • ίϯύΠϧͯ͠Ͱ͖ͨόΠφϦΛμΠφϛοΫϦϯΫ
How does it work? (Inline::C)
How does it work? (Inline::Python) • Python.hΛXSϨΠϠͰΈࠐΜͰ͍Δ • Python.hΛͬͯpythonίʔυΛevalͯ͠result objectʹ͢Δ
• result objectΛperlίʔυʹม • Python.hͰpythonίʔυ͔Β໊લۭؒใΛҾͬ͜ൈ͘ • Ҿͬ͜ൈ໊͍ͨલۭؒΛperlίʔυʹຒΊࠐΉ • Pythonͷݺͼग़͠෦Λϥοϓͯ͠perl͔Βݺͼग़͠Մೳʹ͢Δ • ͳͲ……
Why Inline?
Why Inline? • > The most obvious reason is performance.
• > you may be able to remove a bottleneck in your Perl code by using another language
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ʹର͢Δݴٴͳ͠)
࣮ࡍͳͥInlineΛ? • Perlͷࢿ࢈͕͋ΓɼͲ͏ͯ͠PerlͰΔඞཁ͕͋Γɼ ͦͯ͠PerlͰύϑΥʔϚϯε͕ग़ͳ͍෦Λิ͏ • ྫ͑ܭࢉ
Seriously?
Seriously? • (ঢ়گʹΑͬͯ) Ϛδ
Benchmark • https://gist.github.com/moznion/83dfd5cccb6a8d59a7a7e9e101d64cf8
Benchmark
Pros/Cons
Pros • طଘࢿ࢈Λ্ͬͨͰ؆୯ʹυʔϐϯά͕Մೳ • ଞͷݴޠΛૉʹॻ͚ΔͷͰɼXSΑΓൺֱతͱ͖͍ͬͭ͢ [ཁग़య] • https://metacpan.org/pod/distribution/Inline-C/lib/Inline/C/Cookbook.pod • ο
Cons • ىಈ࣌ͷΦʔόϔου͕͋Δ • ڥߏங͕େม • ଈࢮ͢ΔՄೳੑ͕͋Δ
Management Cost • ॲཧܥ͕2ͭ (͋Δ͍ͦΕҎ্) ʹͳΔίετ • ։ൃڥඋ͕͠ΜͲ͍ (όʔδϣϯϩοΫ) •
ຊ൪ڥඋ͠ΜͲ͍ • όʔδϣϯϩοΫ • όʔδϣϯΞοϓ • Inline::X ͕͏Ϟδϡʔϧͷόʔδϣϯཧ
ଈࢮʁ
Mentality • ͦΕ͔ΓͳΜͱ…… • ͞·͟·ͳঢ়گʹΑΔ (ใྔ͕ແ)
GLUE language
άϧʔݴޠ • ଞͷιϑτΣΞίϯϙʔωϯτͱ࿈ܞͤ͞ΔͨΊͷݴޠ • e.g. γΣϧεΫϦϓτ
PerlͷཱͪҐஔ • ϓϩάϥϛϯάݴޠPerlΑΓൈਮ • > ಉ࣌ʹଟ͘ͷϑΝΠϧϓϩηεͱ௨৴Ͱ͖Δͱ͍͏͜ͱ͕ɺ Perl͕ྑ͍άϧʔݴޠͰ͋Δཧ༝ (ͷͻͱͭ) ʹͳ͍ͬͯΔ •
> ΤΫεςϯγϣϯϞδϡʔϧʹΑͬͯ෦ʹଞͷͷΛΈࠐ ΊΔ͜ͱ
Glue => Inline • Inlineͱάϧʔݴޠͷࢥڧؔ͘࿈͍ͯ͠Δ • PerlΛ࣮ߦج൫ͱͯ͠ଞͷݴޠΛΈࠐΜͰಈ͔͢ • Perlͷࢿ࢈ͱଞͷݴޠͷࢿ࢈ͱΛγʔϜϨεʹ݁ͼ͚ͭΔ͜ͱ͕ Ͱ͖Δ
͔͠͠άϧʔݴޠͬͯฉ͔ͳ͘ͳΓ·ͨ͠Ͷ • Over HTTPͷAPI callingͷൃୡ • ݴޠΑΓԼͷϨΠϠͷΠϯλʔϑΣʔε͕ͬͨͷͰɼͦ͜ ͰؤுΔඞཁ͕ബ͘ͳͬͨͱ͍͏ͷ͋Γͦ͏ • ͔ͭͯͷCORBASOAPXMLRPCΑΓஅવʹڥΑ͘ͳͬͨ
• ͱݴ͑Over HTTPͰAPIΛݺͼग़ͦ͏ͱ͢ΔͱϨΠςϯγ͕͋Δ • ͦͷϨΠςϯγ͕ແࢹͰ͖ͳ͘ͳΔλΠϛϯάଘࡏ͢Δ • ͦͷ࣌ͷͨΊͷग़ϋονͱͯ͠Inline͑Δ ͔͠͠άϧʔݴޠͬͯฉ͔ͳ͘ͳΓ·ͨ͠Ͷ
ର͢ΔLLVMͷख๏ • ҃ΔݴޠΛ҃Δݴޠʹม͢Δͱ͍͏ख๏ • ໌Β͔ʹਖ਼͍͠ʂʂʂʂʂ • ͜Εʮάϧʔݴޠʯ͕ਰୀ͍ͯͬͨ͠ҰҼͰͳ͍͔
Perl6ͷເ • use Inline::Perl5 • use Inline::Go • ͦͯ͠ଞݴޠͷมcompiler •
Java • Perl5 • JavaScript • ͳΜͰॻ͚Δ!!!
ॴײ
ॴײ • Perlͷطଘࢿ࢈͕ࢧతͰɼͲ͏ͯ͠ΘͶͳΒͳ͍߹ બࢶͷҰͭʹͳΓ͑Δ • ʮશ෦ॻ͖ͧ͢ʂʂʂʯ͕Ͱ͖ͳ͍͜ͱੈͷதʹଟ͍ • ͦͯ͠ಘͯͯ͠ʮશ෦ॻ͖ͧ͢ʂʂʂʯϙγϟΓ͕ͪ • ο
ॴײ • ͓ͱͳ͘͠XSͰॻ͘ͱ͍͏ํ๏͋Δ • ͓ͦΒ͘ϝϯόʔ͕XSͷΤΩεύʔτͰ͋Δඞཁ͕͋Δ • ͦ͏Ͱͳ͍߹υΩϡϝϯτʹ͋ΔΑ͏ʹ։ൃʹ͕͔͔࣌ؒΔ • ͔ͦ͠͠͏ͳͬͯ͘ΔͱPerlͰॻ͍͍ͯΔͷ͔Կͳͷ͔Θ͔Βͳ͘ ͳΔͧ……
ॴײ • ʮPerlͷطଘࢿ࢈͕ࢧతͰɼͲ͏ͯ͠ΘͶͳΒͳ͍߹ʯͰͳ͍ ߹ • ಛʹ͏ඞཁͳ͍ͱࢥ͏…… • ʮͲ͏ͯ͠Perlॻ͖ͨ͘ͳ͍ʂʂʯͱ͍͏γνϡΤʔγϣϯʹର͢Δग़ ϋονͰͳ͍ɹ •
ʮPerlॻ͚ͳ͍͚Ͳϫϯνϟϯ……ʯͱ͔ͳ͍ • ਓΛڻ͔ͤΔͷ͕తͷ߹༗ޮ (ʁ) ͔͠Εͳ͍
ॴײ • > Maybe the best reason is "Because you
want to!". Diversity keeps the world interesting. TMTOWTDI! • ࣄͩͱͦ͏ݴ͓ͬͯΕΜ……
·ͱΊ
·ͱΊ • PerlͷInlineϞδϡʔϧʹ͍ͭͯ͝հΛ͠·ͨ͠ • PerlͷInlineϞδϡʔϧͷpros/consʹ͍ͭͯઆ໌͠·ͨ͠ • ओʹੑೳ໘Ͱͷڧ͞Λૂ͑·͢ • άϧʔݴޠͷࠓੲʹ͍ͭͯ͠·ͨ͠ •
InlinePerl͕ݏʹͳͬͨਓͷͨΊͷग़ϋονͰͳ͍
མึͻΖ͍: ͜Μͳʹ͋ΔInlineϞδϡʔϧ
͜Μͳʹ͋ΔInlineϞδϡʔϧ
͜Μͳʹ͋ΔInlineϞδϡʔϧ
͜Μͳʹ͋ΔInlineϞδϡʔϧ • DAVIDO/Inline::CPP • RHOELZ/Inline::Lua • MIYAGAWA/Inline::Basic • RRS/Inline::Tcl •
NEILW/Inline::ASM • etc...
མึͻΖ͍: InlineϞδϡʔϧͷॻ͖ํ
InlineϞδϡʔϧͷॻ͖ํ • આ໌͢Δʹ͋·Γʹ͕࣌ؒͳ͍͜ͱ͕༧͞ΕΔͷͰͬ͘͟Γ • registerॻ͘ • buildॻ͘ • load/bindॻ͘ •
ʂʂʂ (͜͜ʹࢸΔ·Ͱʹͱͯͭͳ͍࿑ྗΛཁ͢Δ)
InlineϞδϡʔϧͷॻ͖ํ • Inline::CͱInline::PythonΑ͘Ͱ͖͍ͯΔͷͰࢀߟʹͳΔͱࢥ͍·͢
Q?