ODG-Record
view release on metacpan or search on metacpan
lib/ODG/Record/Discussion.pod view on Meta::CPAN
=head1 DISCUSSION
This document maintains some thoughts of Record Iterators and Moose.
ODG::Record is designed for efficient streaming, i.e. accessing
one-record-at-a-time. For conventional record iterators, a new row
object is created for each record, slots are initialized, data are
filled and types are checked. Not all of this is desirable.
=head1 Object Recycling
If every row based record, populates in the same manner, it is hugely
inefficient to instantiate a new object for each record. This is
especially true of Moose-based class. ( This is not a knock against
Moose. ODG::Record uses Moose extensively. )
The approach taken by this module is to instantiate a single object and
changing the data for that object. To do this, a ArrayRef data slot is
created. When the next record is used. The ArrayRef is pointed to a
different Array, i.e. the next record. In not incurring the expensive
of object instantiation for each record we have a huge performance win.
(See tables below.)
The downside is that the checking / validation in new object creation
is lost. This may or not be acceptable depending on the situation.
Generally, when the records are well-defined and well-maintained,
i.e. from a database, this is not an issue. The data from one record
to the next is fairly consistent.
Encapsulation is also be lost. Again, whether this is acceptable
depends on the situation. There are several methods of object
recycling ( as opposed to creating a new object). They are:
Notably, encapsulation is not lost for the entire object. It is done
only for the attributes that point to the _data slot. These are
identified by the meta-attribute trait, index, as well as a non-negative
integer specifying the position in the ArrayRef.
=head1 Performance
The _data slot can be accessed in a number of ways:
* creating a new ODG::Recrod object.
* using a standard accessor,
* using an lvalue accessor (not officially supported
by Moose -and- may break encapsulation. ( Since this is Moose,
other Moose techniques can be used for validation, e.g. after method)
* direct access (breaks encapsulation).
=head2 _data assignment performance
Here is a comparison of methods for placing new data in the record
object on an Intel(R) Xeon(TM) CPU 3.06GHz processor:
Data has 5 elements: 1..5
Rate new object moose accessor lvalue moose direct access
new object 1268/s -- -99% -100% -100%
moose accessor 222222/s 17428% -- -56% -78%
lvalue moose 500000/s 39337% 125% -- -50%
direct access 1000000/s 78775% 350% 100% --
Data has 25 elements: 1..25
( run in 0.647 second using v1.01-cache-2.11-cpan-5a3173703d6 )