Perl6 meets JVM

Tokuhiro Matsuno
Tokuhiro MatsunoSoftware Engineer at LINE Corp
Perl6 + JVM
tokuhirom
YAPC::Asia 2016
Self Introduction
Amon2,Harriet, Localizer,
Minilla, Test::Requires,
etc.
Perl6?
This is Rakudo Star, a useful,
usable Perl 6 distribution for
"early adopters".
曰く、
useful??
BTW,
Products
• nqp: Perl6 subset, to write Perl6 interpreter
• rakudo: One of Perl6 implementation
VM Support
• Parrot: VM for…
• MoarVM: VM for Perl6
• JVM: VM for Java ← Today’s topic
Why?
Because, I’m using
Java for $DAYJOB
You can use java
libraries, instead of poor
Perl6 libraries.
perl6-j is probably useful
for Java developers
で?
How do I install Perl6?
wget http://rakudo.org/
downloads/star/rakudo-
star-2015.07.tar.gz
tar xzvf rakudo-
star-2015.07.tar.gz
perl Configure.pl
—backends=jvm
—gen-nqp
--prefix=$HOME/perl6
• make
• make install
Easy
brew install rakudo-star
—with-jvm
Then…
Evaluation point as a
Web developer
• Start-up speed
• File access
• JSON processing
• HTTP client
• HTTP Server(Performance)
• Access to mysql
• use java libraries
Start-up speed
time ./install/bin/perl6-j 
-e 'say "Hello, YAPC”’
Hello, YAPC
./install/bin/perl6-j -e 'say "Hello, YAPC”'
17.32s user 0.51s system 254% cpu
6.995 total
Slow!
Is JVM slow?
No!
> javac Hello.java
> time java Hello
Hello
java Hello 0.12s user 0.03s
system 116% cpu 0.130 total
time perl -E 'say "Hello, YAPC"'
Hello, YAPC
perl -E 'say "Hello, YAPC"' 0.04s
user 0.04s system 83% cpu 0.094
total
433 times slower
time /usr/local/bin/perl6-m -e 'say "hello"'
hello
/usr/local/bin/perl6-m -e 'say "hello"' 0.31s
user 0.04s system 97% cpu 0.360 total
2. File Access
say slurp("/etc/
passwd")
It works.
3. JSON
use JSON::Tiny;
(bundled)
> use JSON::Tiny;
> from-json(‘[1,2,true]').perl
[1, 2, Bool::True]
to-json(
{“a"=>5.16,"b"=>false,"c"=>[1..5]}
)
4. HTTP Client
use LWP::Simple;
(Bundled)
> use LWP::Simple
> LWP::Simple.get("http://
64p.org")
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML
1.0 Transitional//EN" "http://www.w3.o$
g/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
useful!
But there’s no legacy
encoding support.
> LWP::Simple.get("http://
google.co.jp")
Unknown encoding 'shift_jis'
5. DB Access
DB Access uses
NativeCall
NativeCall?
FFI - Foreign Function
Interface
Call C API from Perl6
JNA on JVM
ちな Perl5 だと
require DynaLoader;
DynaLoader::dl_install_xsub(
"myfork",
DynaLoader::dl_find_symbol(
DynaLoader::dl_load_file("libc.so"),
'fork'
),
);
myfork();
Joke…
use FFI;
そして Perl6 へ。。
use DBDish;
my $dbh =
DBIish.connect('SQLite', :
database<thefile.sqlite3>);
cp /usr/local/Cellar/sqlite/
3.8.9/lib/libsqlite3.dylib ./
Supported DB:
PostgreSQL
MySQL
SQLite3
use DBIish;
my $dbh =
DBIish.connect('mysql', :host<127.0.0.
1>, :port(3306), :database<mysql>, :us
er<root>, :password(''));
my $sth = $dbh.prepare('SHOW
TABLES');
$sth.execute();
my $arrayref = $sth.fetchall_arrayref();
$arrayref.perl.say;
How do I call JNI
methods?
sub mysql_affected_rows( OpaquePointer
$mysql_client )
returns int32
is native('libmysqlclient')
{ ... }
It’s easy!!!
You can call C APIs!
6. HTTP Server
HTTP::Easy::PSGI
(bundled)
use HTTP::Easy::PSGI;
my $http = HTTP::Easy::PSGI.new(:port(8080));
my $app = sub (%env) {
my $name = %env<QUERY_STRING> || "World";
return [ 200, [ 'Content-Type' => 'text/plain' ], [ "Hello
$name" ] ];
}
$http.handle($app);
with perl6-m
• ab -n 50 -c 1 http://127.0.0.1:8080/
• Requests per second: 5.95 [#/sec] (mean)
with perl6-j
• ab -n 50 -c 1 http://127.0.0.1:8080/
• Requests per second: 10.60 [#/sec] (mean)
10 threads + perl6-j
• ab -c 10 -n 1000 http://127.0.0.1:8080/
• Requests per second: 22.91 [#/sec] (mean)
Single thread + perl6-j
• single thread
• ab -c 10 -n 1000 http://127.0.0.1:8080/
• Requests per second: 17.84 [#/sec] (mean)
ab -n 1000 -c 10
http://127.0.0.1:8080/
Time per request:
550.895 [ms] (mean)
(It doesn’t support
concurrency)
7. Call Java methods
use
java::util::zip::CRC32:fro
m<
java>;
my $crc = CRC32.new();
for 'Hello, Java'.encode('utf-8') {
$crc.update($_)
}
$crc.getValue.say;
it works.
8. GUI
my $frame =
JFrame.new("Helloworl
d");
$frame.setDefaultClose
Operation(1);
my $label = JLabel.new("Hello,
world");
$frame.getContentPane.add($labe
l);
$frame.pack();
$frame.setVisible(True)
Demo
use
My::Own::Class:from<
Java>:jar<hoge.jar>
Conclusion
There is some issues.
But practical than I
thought
1 of 89

More Related Content

What's hot(20)

JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor BuzatovićJavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association4.1K views
Perl Dist::Surveyor 2011Perl Dist::Surveyor 2011
Perl Dist::Surveyor 2011
Tim Bunce2.7K views
Graal in GraalVM - A New JIT CompilerGraal in GraalVM - A New JIT Compiler
Graal in GraalVM - A New JIT Compiler
Koichi Sakata2.7K views
NashornNashorn
Nashorn
Everett Toews1.7K views
Fluentd in Co-WorkFluentd in Co-Work
Fluentd in Co-Work
Makoto Haruyama9K views
Shall we play a game?Shall we play a game?
Shall we play a game?
Maciej Lasyk519.9K views
Hack & Fix, Hands on ColdFusion Security TrainingHack & Fix, Hands on ColdFusion Security Training
Hack & Fix, Hands on ColdFusion Security Training
ColdFusionConference1.1K views
zlm-cythonzlm-cython
zlm-cython
Vladimir Ulogov431 views
CPAN TrainingCPAN Training
CPAN Training
Pedro Figueiredo2.5K views
ZLM-Cython Build you first moduleZLM-Cython Build you first module
ZLM-Cython Build you first module
Vladimir Ulogov551 views
Modern PHP Ch7 Provisioning Guide 導讀Modern PHP Ch7 Provisioning Guide 導讀
Modern PHP Ch7 Provisioning Guide 導讀
Chen Cheng-Wei2.9K views
Ruby 2.4 InternalsRuby 2.4 Internals
Ruby 2.4 Internals
Koichi Sasada1.6K views
Middleware as Code with mrubyMiddleware as Code with mruby
Middleware as Code with mruby
Hiroshi SHIBATA5.2K views

Similar to Perl6 meets JVM(20)

GOTO Night with Charles Nutter SlidesGOTO Night with Charles Nutter Slides
GOTO Night with Charles Nutter Slides
Alexandra Masterson1.3K views
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in Clojure
Troy Miles623 views
Beyond JVM - YOW Melbourne 2013Beyond JVM - YOW Melbourne 2013
Beyond JVM - YOW Melbourne 2013
Charles Nutter3.3K views
Jruby synergy-of-ruby-and-javaJruby synergy-of-ruby-and-java
Jruby synergy-of-ruby-and-java
Keith Bennett1.1K views
Plack on SL4A in Yokohama.pm #8Plack on SL4A in Yokohama.pm #8
Plack on SL4A in Yokohama.pm #8
Yoshiki Kurihara2.5K views
Leaner microservices with Java 10Leaner microservices with Java 10
Leaner microservices with Java 10
Arto Santala558 views
Pugs: A Perl 6 ImplementationPugs: A Perl 6 Implementation
Pugs: A Perl 6 Implementation
Audrey Tang4.2K views
De Java 8 ate Java 14De Java 8 ate Java 14
De Java 8 ate Java 14
Víctor Leonel Orozco López1.3K views
De Java 8 a Java 11 y 14De Java 8 a Java 11 y 14
De Java 8 a Java 11 y 14
Víctor Leonel Orozco López1.9K views
First Day With J RubyFirst Day With J Ruby
First Day With J Ruby
Praveen Kumar Sinha896 views
HotSpotコトハジメHotSpotコトハジメ
HotSpotコトハジメ
Yasumasa Suenaga7.3K views
DevOps in PHP environment DevOps in PHP environment
DevOps in PHP environment
Evaldo Felipe160 views
Racing with DroidsRacing with Droids
Racing with Droids
Peter Hlavaty3.5K views
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
Burke Libbey1.2K views
Node.js und die Oracle-DatenbankNode.js und die Oracle-Datenbank
Node.js und die Oracle-Datenbank
Carsten Czarski2.1K views

More from Tokuhiro Matsuno(20)

20190126 yapc tokyo keynote 20190126 yapc tokyo keynote
20190126 yapc tokyo keynote
Tokuhiro Matsuno9.1K views
Plenv and perl build, and search.cpan.orgPlenv and perl build, and search.cpan.org
Plenv and perl build, and search.cpan.org
Tokuhiro Matsuno1.3K views
Yapc fukuoka crustYapc fukuoka crust
Yapc fukuoka crust
Tokuhiro Matsuno2.5K views
Perl6 と web 開発とPerl6 と web 開発と
Perl6 と web 開発と
Tokuhiro Matsuno910 views
Lineにおけるspring frameworkの活用Lineにおけるspring frameworkの活用
Lineにおけるspring frameworkの活用
Tokuhiro Matsuno33.7K views
Openjdk 入門してみた話Openjdk 入門してみた話
Openjdk 入門してみた話
Tokuhiro Matsuno3.2K views
Java web application testingJava web application testing
Java web application testing
Tokuhiro Matsuno7.7K views
[jjug] Java と Benchmark[jjug] Java と Benchmark
[jjug] Java と Benchmark
Tokuhiro Matsuno4.4K views
Devel::NYTProf::ApacheDevel::NYTProf::Apache
Devel::NYTProf::Apache
Tokuhiro Matsuno1.8K views
ArcherArcher
Archer
Tokuhiro Matsuno3.7K views
MySQL::NameLockerMySQL::NameLocker
MySQL::NameLocker
Tokuhiro Matsuno1.5K views
Inside MFInside MF
Inside MF
Tokuhiro Matsuno1.1K views
Web Application FLowWeb Application FLow
Web Application FLow
Tokuhiro Matsuno1K views
madeye agentsmadeye agents
madeye agents
Tokuhiro Matsuno1.1K views
madeye classesmadeye classes
madeye classes
Tokuhiro Matsuno843 views

Recently uploaded(20)

Perl6 meets JVM