clintongormley / Elastic-Model

Use ElasticSearch as a NoSQL database in Perl
9 stars 8 forks source link

Performance of Elastic::Model::UID::new_from_store re Moose type constraints #21

Closed timbunce closed 11 years ago

timbunce commented 11 years ago

On my system (perl 5.10) each call to Elastic::Model::UID::new_from_store takes 1.36ms.

That adds up fast.

Much of the cost is in Moose::Meta::TypeConstraint checking.

I see the Elastic::Model::UID doesn't use PACKAGE->meta->make_immutable; That may help (here and in other packages).

Also, perhaps you'd consider dropping the Str and/or Maybe[Str] 'isa' declarations since they add relatively little value.

clintongormley commented 11 years ago

Hiya @timbunce

The UID object creation time has been halved by making the class immutable. Also, i've added some optimization when creating new stub doc objects, so retrieving docs from elasticsearch performs a lot better than it did.

Released in v0.18 - https://metacpan.org/release/DRTECH/Elastic-Model-0.18/

I didn't remove the type constraints on routing etc, as there are quite a few users creating their own UID objects, and I'd prefer to make it easy to spot problems early. Although I could be persuaded.

Next stop is inlining the inflation/deflation process which will be a big performance gain.