Mouse type constraints in XS
MouseのXS化*1が進みつつあります。
0.40_04ではtype constraintsを全面的にXSで実装しました。生成されるコードを徹底的にXS化したため,かなり高速になりました。
以下はTC付きアクセサに値をセットする場合のベンチマークの結果です。
Mouse/benchmarks/type_constraints.pl:
Perl/5.10.1 in i686-linux
Moose/0.92 (Class::MOP/0.94)
Mouse/0.40_03
Class::XSAccessor/1.03
SETTING for simple attributes
Rate Moose Mouse C::XSAccessor
Moose 643109/s -- -62% -62%
Mouse 1686587/s 162% -- -1%
C::XSAccessor 1703286/s 165% 1% --
SETTING for attributes with type constraints 'Int'
Rate Moose Mouse C::XSAccessor
Moose 204799/s -- -87% -88%
Mouse 1531040/s 648% -- -9%
C::XSAccessor 1686587/s 724% 10% --
SETTING for attributes with type constraints 'Foo'
Rate Moose Mouse C::XSAccessor
Moose 194606/s -- -79% -88%
Mouse 927395/s 377% -- -41%
C::XSAccessor 1571965/s 708% 70% --
SETTING for attributes with type constraints 'ArrayRef[Int]'
Rate Moose Mouse C::XSAccessor
Moose 66991/s -- -92% -95%
Mouse 865569/s 1192% -- -42%
C::XSAccessor 1485435/s 2117% 72% --TCを指定しない状態だとClass::XSAccessorとほぼ同じです。Intのような単純型だと約10%のロスですが,あまり変わりません。isaチェックやパラメータをとる型のように複雑なものだと速度はだいぶ落ちるものの,PurePerlであるMooseにTCを加えないものよりも高速です。
正規リリースはまだ先ですが,中間報告でした。