From: Nigel Metheringham Date: Wed, 11 Feb 2009 21:07:05 +0000 (+0000) Subject: Documentation update on startup speed X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bc96f2606c021439a25e1376db53fe418cf4bb49;p=dbsrgits%2FDBIx-Class-Historic.git Documentation update on startup speed --- diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 216d71b..110091f 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -812,7 +812,7 @@ To do this simply use L. my $hash_ref = $rs->find(1); Wasn't that easy? - + =head2 Get raw data for blindingly fast results If the L solution @@ -1618,5 +1618,67 @@ You could then create average, high and low execution times for an SQL statement and dig down to see if certain parameters cause aberrant behavior. You might want to check out L as well. +=head1 STARTUP SPEED + +L programs can have a significant startup delay +as the ORM loads all the relevant classes. This section examines +techniques for reducing the startup delay. + +These tips are are listed in order of decreasing effectiveness - so the +first tip, if applicable, should have the greatest effect on your +application. + +=head2 Statically Define Your Schema + +If you are using +L to build the +classes dynamically based on the database schema then there will be a +significant startup delay. + +For production use a statically defined schema (which can be generated +using L to dump +the database schema once - see +L and +L for more +details on creating static schemas from a database). + +=head2 Move Common Startup into a Base Class + +Typically L result classes start off with + + use base qw/DBIx::Class/; + __PACKAGE__->load_components(qw/InflateColumn::DateTime Core/); + +If this preamble is moved into a common base class:- + + package MyDBICbase; + + use base qw/DBIx::Class/; + __PACKAGE__->load_components(qw/InflateColumn::DateTime Core/); + 1; + +and each result class then uses this as a base:- + + use base qw/MyDBICbase/; + +then the load_components is only performed once, which can result in a +considerable startup speedup for schemas with many classes. + +=head2 Explicitly List Schema Result Classes + +The schema class will normally contain + + __PACKAGE__->load_classes(); + +to load the result classes. This will use L +to find and load the appropriate modules. Explicitly defining the +classes you wish to load will remove the overhead of +L and the related directory operations:- + + __PACKAGE__->load_classes(qw/ CD Artist Track /); + +If you are instead using the L +syntax to load the appropriate classes there is not a direct alternative +avoiding L. =cut diff --git a/lib/DBIx/Class/Manual/FAQ.pod b/lib/DBIx/Class/Manual/FAQ.pod index bcdde3a..9c19d31 100644 --- a/lib/DBIx/Class/Manual/FAQ.pod +++ b/lib/DBIx/Class/Manual/FAQ.pod @@ -497,6 +497,16 @@ point of view: $resultset->set_primary_key(@column); +=item How do I make my program start faster? + +Look at the tips in L + +=item How do I reduce the overhead of database queries? + +You can reduce the overhead of object creation within L +using the tips in L +and L + =back =head2 Notes for CDBI users