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.2k
The World of Inline Module
YAPC::Okinawa 2018 Onnasonの資料です
moznion
March 03, 2018
Tweet
Share
More Decks by moznion
See All by moznion
RuboCopのカスタムCopを書いてContributionしてみる - Contributing a Custom Cop to RuboCop: A Hands-on Experience
moznion
0
41
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.6k
ソフトウェア開発における 「設計」と「パフォーマンス」の相互作用 / Interaction Between Design and Performance on Software Development
moznion
11
6.8k
Javaカードの世界 / The world of Java Card
moznion
8
13k
無限にスケールする上に自律的なJenkinsに見る夢~AWS篇~ / Dream of autonomous and infinite scalable Jenkins with AWS
moznion
21
6.9k
そして物語は更に何度目かのアプリ内通知再実装を迎える / Reimplement in app notification again
moznion
1
3.7k
Web Application Good Error Message (and Bad Error Message)
moznion
0
5.4k
Other Decks in Technology
See All in Technology
ロボットアームを遠隔制御の話 & LLMをつかったIoTの話もしたい
soracom
PRO
1
260
LLVM/ASMを使った有限体の高速実装
herumi
0
110
エンジニア向け会社紹介資料
caddi_eng
15
250k
Zero Data Loss Autonomous Recovery Service サービス概要
oracle4engineer
PRO
0
3.2k
Agile in Automotive Industry, puzzles and lights.
hiranabe
0
170
Optuna: a Black-Box Optimization Framework
pfn
PRO
1
100
「自動テストのプラクティスを効果的に学ぶためのカードゲーム」 ( #sqip2024 )
teyamagu
PRO
0
120
ロリポップ! for Gamersを支えるインフラ/lolipop for gamers infrastructure
takumakume
0
120
AI でアップデートする既存テクノロジーと、クラウドエンジニアの生きる道
soracom
PRO
2
380
RAGHack: Building RAG apps in Python
pamelafox
0
160
The XZ Backdoor Story
fr0gger
0
3k
忙しい人のためのLangGraph概要まとめ
__ymgc__
1
150
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
322
23k
We Have a Design System, Now What?
morganepeng
48
7.1k
YesSQL, Process and Tooling at Scale
rocio
167
14k
Into the Great Unknown - MozCon
thekraken
28
1.4k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
190
16k
Music & Morning Musume
bryan
46
6k
Writing Fast Ruby
sferik
623
60k
Large-scale JavaScript Application Architecture
addyosmani
508
110k
Building a Modern Day E-commerce SEO Strategy
aleyda
35
6.8k
KATA
mclloyd
27
13k
Pencils Down: Stop Designing & Start Developing
hursman
119
11k
Optimising Largest Contentful Paint
csswizardry
29
2.8k
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?