Posts
In these days, Japanese perl mongers trying to inject a x86 binary code to the perl world with pure perl.
DynaLoader::dl_install_xsub inject binary code, that can call as CV(coderef).
Following is a sample code, call the fork(2).
use DynaLoader;
my $s = join('',
"\x31\xc0", # xor %eax,%eax
"\xb0\x02", # mov $0x2,%al
"\xcd\x80", # int $0x80
"\xc3", # ret
);
DynaLoader::dl_install_xsub(
'myfork',
unpack("L",pack("P*",$s))
);
&myfork;
Enjoy!
Me(tokuhirom) and Yappo works for the Mouse in Shika-based branch.
Followings are Changes list.
- method inject at apply roles(tokuhirom)
- apply multi roles at once(yappo)
- inline constructor at make_immutable(tokuhirom,sartak)
- inline destructor at make_immutable(tokuhirom)
- do not load Test::Exception at runtime(tokuhirom)
- added MouseX::Types(yappo)
- added Mouse::Meta::Class->create(_anon_class)?(tokuhirom)
- user type definition(yappo)
- added coercion support(yappo)
runtime speed is good enough.
Class::MOP: 0.71
Moose: 0.62
Mouse: 0.12
---- new
Rate MooseOne MouseOne
MooseOne 89286/s -- -4%
MouseOne 93458/s 5% --
---- new,set
Rate MouseOne MooseOne
MouseOne 62500/s -- -4%
MooseOne 64935/s 4% --
My work is finished.
I wrote small tool for measurement process size.
Following is the result.
perl> package F; use Moose;
5,185,536
perl> use Mouse;
700,416
perl> use Shika;
581,632
perl> use Class::MOP;
1,957,888

Moose uses over 5MB.This is too much...
script is here: http://svn.coderepos.org/share/lang/perl/misc/memory-shell.pl
some people says "mouse is fast in loading time, but!!! mouse is slower than moose at runtime". ok, this is true in the latest released version of Mouse!
------ new
Rate MouseDefault MooseImmutableBuild ClassAccessor MooseImmutableDefault MouseImmutableDefault ShikaDefault Popo
MouseDefault 12658/s -- -73% -77% -82% -84% -91% -95%
MooseImmutableBuild 47619/s 276% -- -14% -33% -38% -67% -81%
ClassAccessor 55556/s 339% 17% -- -22% -28% -61% -78%
MooseImmutableDefault 71429/s 464% 50% 29% -- -7% -50% -71%
MouseImmutableDefault 76923/s 508% 62% 38% 8% -- -46% -69%
ShikaDefault 142857/s 1029% 200% 157% 100% 86% -- -43%
Popo 250000/s 1875% 425% 350% 250% 225% 75% --
I'm implement the Meta::Method::Constructor & Meta::Method::Desctructor for Mouse.This makes Mouse 500% faster at runtime.
and, some people says "Why Shika is FAST???" ok, i don't know ;) this is japanese XS magicians work.
benchmark script is here:http://svn.coderepos.org/share/lang/perl/Shika/trunk/benchmark/new-get-set.pl
this code will die.by "Attribute (foo) is required"
{
package Parent;
use Moose;
}{
package Child;
use Moose;
extends 'Parent';
}Parent->meta->add_attribute(
'foo' => (
required => 1,
)
);Child->new();
but, following code doesn't throw error.
{
package Parent;
use Moose;
}{
package Child;
use Moose;
extends 'Parent';
__PACKAGE__->meta->make_immutable();
}Parent->meta->add_attribute(
'foo' => (
required => 1,
)
);Child->new();
conclusion
Moose doesn't mention to this operation.
run -Ilib -e 'package F; use Moose'
total = 0.3154765
run -Ilib -e 'package F; use Mouse'
total = 0.0436822
run -Ilib -e 'package F; use Shika'
total = 0.0283219
ok, shika has few features =)
http://svn.coderepos.org/share/lang/perl/Shika/trunk/benchmark/loading-time.pl
【following ups】
in shika based branch@r6714!yay!run -Ilib -e 'package F; use Mouse'
total = 0.0307623
main => Mouse.pm =>
Mouse => strict.pm =>
Mouse => warnings.pm =>
warnings => Carp.pm =>
Carp => Exporter.pm =>
Mouse => base.pm =>
base => vars.pm =>
vars => warnings/register.pm =>
Mouse => Mouse/Util.pm =>
Mouse::Util => Scalar/Util.pm =>
Scalar::Util => List/Util.pm =>
List::Util => XSLoader.pm =>
Mouse::Util => MRO/Compat.pm =>
MRO::Compat => Class/C3.pm =>
Class::C3 => Class/C3/XS.pm =>
Mouse => Mouse/Meta/Attribute.pm =>
Mouse => Mouse/Meta/Class.pm =>
Mouse => Mouse/Object.pm =>
Mouse => Mouse/TypeRegistry.pm =>
Exporter => Exporter/Heavy.pm =>
ANSWER is NO and YES.
Main target of the HTTP::Engine is FastCGI/ModPerl.
1. CGI is not a main target.
2. HTTP::Engine 0.0.x seriese uses a lot of memory.Shika makes smart process.
3. HTTP::Engine is middleware. not a application.middleware should use small memory.
4. Short compile time makes easy development.
5. As a side effect, HTTP::Engine::Interface::CGI is faster than before.
Shika is a new class builder.Current main maintener is tokuhirom and yappo.
Shika's use case is very simple. Jus a HTTP::Engine.
- Moose has cool API
- Moose uses too much loading time for HTTP::Engine
- perl -e 'use Moose' 0.30s user 0.01s system 94% cpu 0.330 total
- Moose uses a lot of memory.
- We need a lightweight class builder, based on cool API.
- We don't need a MOP.
- We can write faster implementation
- no MOP;
- use XS;(gfx can write very fast XS code =)
- type check is optional(in development mode)
- no eval.
- Shika is Moose incompaible.
- Shika supports
- opional type constraints
- Role, with, has, before, around, after, etc.
- Mouse is the answer one of this problem. I know.
Current project status is
- development release
- no XS yet
- loading time is 0.88sec => 0.11sec
The killer feature of this version is "shttpd support"(http://shttpd.sourceforge.net/).
Run the httpd by JavaScript!
v8ext.LoadBinary("org.coderepos.shttpd");
var SHTTPD = org.coderepos.shttpd.SHTTPD;var httpd = new SHTTPD(8080);
httpd.RegisterURI("/", function (r) {
r.Print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
r.Print("<html><body>Hello, v8 world</body></html>");
r.SetFlags(SHTTPD.END_OF_OUTPUT);
});
httpd.StartLoop();
llv8call is a good solution for server side javascript.It is composed of three parts.
1. Core
- builtin functions
- ARGV support
- ENV support
- better interactive mode based on libreadline
v8ext is extension library library for v8. This module makes "easy to extend your application, uses v8".
This module provides 2 methods and 1 property
- v8ext.LoadScript()
- v8ext.LoadBinary()
- v8ext.LibraryPath
3.extension libraries
llv8call respects "batteries included" style.
current version provides:
- sqlite3
- libfcgi
- nspr(NetScape Portable Runtime), this module exports File, TCPSocket, UDPSocket, Process Management, Dir, etc.
- libmemcached
- curl