Because Sometimes Lightspeed is Too Slow
I've pushed Type::Tiny 0.045_03 to CPAN this afternoon. Initial results from CPAN testers seem promising, but if you've got a distribution that uses Type::Tiny it might be worth trying it out with the new version to see if anything breaks. (I don't think anything should!)
The big change in this release is that it adds support for an optional XS backend, which massively boosts the speed of many type constraint checks — especially parameterized types like ArrayRef[InstanceOf["HTTP::Response"]]
. The XS backend is a fork of Mouse's type constraints, and needs to be installed separately. It's called Type::Tiny::XS. (OK; not a very creative name.)
The API for Type::Tiny::XS is kinda rubbishy, but that's OK because it's not designed for end-users. It's designed for frameworks like Type::Tiny to hook into. Because it's standalone, with no non-core dependencies, it should also be suitable for other validation frameworks to make use of too.
The speed up is impressive. Without XS, Type::Tiny can boost the speed of Moose constructors by about 30%; with XS that's over 300%. Coercions benefit too; as does parameter validation.
I'll add that I'm not usually much of a C programmer, so the fact that I was able to do this in very little time is a testament to the clarity and well-organizedness of GFUJI's XS code for Mouse::XS. It was mostly just a case of pulling out the files I wanted, and a bit of search-and-replace to adjust the namespaces. I had a few minor difficulties with EUMM, but thanks very much to alh and the rest of #xs on IRC, those were quickly sorted out.
So really the "lightspeed is too slow" comment applies not just to the Type::Tiny::XS, but also to the tools and community that have built up around Perl and the CPAN. They make it possible to build something like this implausibly quickly. (Even if it's implemented in C!)
I didn't really benchmark the speed ( seems faster ) but it didn't break my software ( or tests ), and I'm doing a lot of type checks and coercions. Thanks for the lib, Type-Tiny is great!