On 10/22/2003 4:01 AM, Tim Bunce wrote:
> On Tue, Oct 21, 2003 at 03:01:20PM -0700, Ovid wrote:
>> Tim Bunce <[EMAIL PROTECTED]> wrote:
>>> 
>>> I'd strongly recommend switching to Storable first. It did have problems
>>> but it's now very robust and far, far, faster than Data::Dumper+eval. 
>>> This small change would yield a big gain.
>> 
>> the data structure for the coverage [...] is so huge that I run out of 
>> memory (and this is on a machine with a couple of gigs of RAM).
> 
> Reading and writing Data::Dumper format is much more memory hungry than
> Storable. Switch to Storable will at least ease the problem.
> 
> I don't have time in the short term to work on the (albeit fairly trivial) 
> change to Storable. If someone can do that and get a new release out then 
> I'll look deeper into the performance issues then.

I tried it, and it does help some. In my very unscientific test[1] it ran about
20% faster. The size of the db file (on disk) was about 75% smaller. I don't
have numbers on RAM usage, but I didn't touch the internal representation so
about all that's saved is the eval overhead.

I've included a patch for Devel/Cover/DB.pm in case someone else wants to try
it. It has *not* been sanctioned by Paul (though he's welcome to it) so use at
your own risk. Obviously, the file format for the database is incompatible with
the current version.

[1] roughly 430 tests in 18 *.t files. Timing done with a wristwatch on a
    single-user WinXP system.

-mjc

*** DB.pm.old   Thu Oct 23 14:58:02 2003
--- DB.pm.new   Thu Oct 23 15:00:01 2003
***************
*** 18,25 ****
  use Carp;
  use Data::Dumper;
  use File::Path;

! my $DB = "cover.4";  # Version 4 of the database.

  sub new
  {
--- 18,26 ----
  use Carp;
  use Data::Dumper;
  use File::Path;
+ use Storable;

! my $DB = "cover.5";  # Version 5 of the database.

  sub new
  {
***************
*** 49,65 ****
          $self->validate_db;
          $file = "$self->{db}/$DB";
          return $self unless -e $file;
!         open F, "<$file" or croak "Unable to open $file: $!";
!         $self->{filehandle} = *F{IO};
      }

-     $self->read if defined $self->{filehandle};
-
-     if (defined $file)
-     {
-         close F or croak "Unable to close $file: $!";
-     }
-
      croak "No input db, filehandle or cover" unless defined $self->{cover};

      $self
--- 50,58 ----
          $self->validate_db;
          $file = "$self->{db}/$DB";
          return $self unless -e $file;
!         $self->read($file);
      }

      croak "No input db, filehandle or cover" unless defined $self->{cover};

      $self
***************
*** 70,111 ****
  sub all_criteria       { @{$_[0]->{all_criteria      }} }
  sub all_criteria_short { @{$_[0]->{all_criteria_short}} }

! sub read
! {
      my $self = shift;
!     local $/;
!     my $db;
!     my $fh = $self->{filehandle};
!     eval <$fh>;
!     croak $@ if $@;
      $self->{cover}     = $db->{cover};
      $self->{collected} = $db->{collected};
      $self->{indent}    = $db->{indent};
!     $self
  }

! sub write
! {
      my $self = shift;
      $self->{db} = shift if @_;
      croak "No db specified" unless length $self->{db};
      $self->validate_db;
!     my $db =
!     {
          cover     => $self->{cover},
          collected => $self->{collected},
          indent    => $self->{indent},
      };
!     local $Data::Dumper::Indent   = $self->indent;
!     local $Data::Dumper::Sortkeys = 1;
!     local $Data::Dumper::Useperl  = 1;  # TODO - remove this when possible
!     my $file = "$self->{db}/$DB";
!     open OUT, ">$file" or croak "Cannot open $file\n";
!     print OUT Data::Dumper->Dump([$db], ["db"]);
!     close OUT or croak "Cannot close $file\n";
!     $self
  }

  sub delete
  {
      my $self = shift;
--- 63,96 ----
  sub all_criteria       { @{$_[0]->{all_criteria      }} }
  sub all_criteria_short { @{$_[0]->{all_criteria_short}} }

! sub read {
      my $self = shift;
!       my $file = shift;
!       my $db   = retrieve($file);
!
      $self->{cover}     = $db->{cover};
      $self->{collected} = $db->{collected};
      $self->{indent}    = $db->{indent};
!     return $self;
  }

! sub write {
      my $self = shift;
      $self->{db} = shift if @_;
      croak "No db specified" unless length $self->{db};
      $self->validate_db;
!
!     my $db = {
          cover     => $self->{cover},
          collected => $self->{collected},
          indent    => $self->{indent},
      };
!
!     Storable::nstore $db, "$self->{db}/$DB";
!     return $self;
  }

+
  sub delete
  {
      my $self = shift;


Reply via email to