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.4k
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
14k
これはPerl? それともRuby? クイズ〜〜〜〜〜!!!- Perl or Ruby Quiz
moznion
3
2.4k
Perl 5 OOP機構30年史 - Perl 5's OOP Mechanism over the past 30 years
moznion
1
930
RuboCopのカスタムCopを書いてContributionしてみる - Contributing a Custom Cop to RuboCop: A Hands-on Experience
moznion
0
65
AWS上に構築する メンテ容易なElasticsearch System / Maintainable Elasticsearch system on AWS
moznion
2
3.9k
PROXY Protocol aware Proxy Server on Node.js
moznion
2
2.5k
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
kargoの魅力について伝える
magisystem0408
0
190
Wantedly での Datadog 活用事例
bgpat
1
120
IVRyエンジニア忘年LT大会2024 クリティカルユーザージャーニーの整理
abnoumaru
0
160
NilAway による静的解析で「10 億ドル」を節約する #kyotogo / Kyoto Go 56th
ytaka23
3
340
どちらを使う?GitHub or Azure DevOps Ver. 24H2
kkamegawa
0
220
Jetpack Composeで始めるServer Cache State
ogaclejapan
2
150
OpenAIの蒸留機能(Model Distillation)を使用して運用中のLLMのコストを削減する取り組み
pharma_x_tech
3
410
実務につなげる数理最適化
recruitengineers
PRO
6
600
Oracle Cloud Infrastructure IaaS 新機能アップデート 2024/9 - 2024/11
oracle4engineer
PRO
1
110
コンテナセキュリティのためのLandlock入門
nullpo_head
2
300
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
170
Kubernetes環境のオブザーバビリティの次の一歩をOpenTelemetryで実現すると何がどうなるの? - CloudNative Days Winter 2024
katzchang
0
130
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
Side Projects
sachag
452
42k
Making Projects Easy
brettharned
116
5.9k
The Cult of Friendly URLs
andyhume
78
6.1k
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
1
160
Producing Creativity
orderedlist
PRO
341
39k
It's Worth the Effort
3n
183
28k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.2k
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?