[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[lintian] 01/01: L::Collect*: Share changelog objects between packages



This is an automated email from the git hooks/post-receive script.

nthykier pushed a commit to branch master
in repository lintian.

commit ffc7174833ff1a3c3fea0d656a976a6783caf351
Author: Niels Thykier <niels@thykier.net>
Date:   Fri Jul 17 23:15:53 2015 +0200

    L::Collect*: Share changelog objects between packages
    
    By sharing the parsed changelog, the memory cache is reduced in size
    by an additional 18%-21%.
    
    Signed-off-by: Niels Thykier <niels@thykier.net>
---
 debian/changelog              |  3 +++
 lib/Lintian/Collect.pm        | 14 +++++++++++++-
 lib/Lintian/Collect/Binary.pm | 18 +++++++++++++++---
 lib/Lintian/Collect/Group.pm  | 13 +++++++++----
 lib/Lintian/Collect/Source.pm | 18 +++++++++++++++---
 5 files changed, 55 insertions(+), 11 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 1c95d51..16218e1 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -17,6 +17,9 @@ lintian (2.5.34) UNRELEASED; urgency=medium
       options: --root, --all, --binary, --source, --udeb.
       They are no longer useful.
 
+  * lib/Lintian/Collect{,/*}.pm:
+    + [NT] Add a shared memory cache that can be used to
+      reduce memory comsumption a bit for sharable objects.
   * lib/Lintian/Data.pm:
     + [NT] Remove references to LINTIAN_ROOT as Lintian::Data
       no longer uses it.
diff --git a/lib/Lintian/Collect.pm b/lib/Lintian/Collect.pm
index e4bb096..812e628 100644
--- a/lib/Lintian/Collect.pm
+++ b/lib/Lintian/Collect.pm
@@ -21,8 +21,10 @@ use strict;
 use warnings;
 use warnings::register;
 
-use Lintian::Util qw(get_dsc_info get_deb_info);
 use Carp qw(croak);
+use Scalar::Util qw(weaken);
+
+use Lintian::Util qw(get_dsc_info get_deb_info);
 
 =encoding utf-8
 
@@ -252,6 +254,16 @@ sub is_non_free {
     return $self->{is_non_free};
 }
 
+# Internal sub for providing a shared storaged between multiple
+# L::Collect objects from same group.
+#
+# sub _set_shared_storag Needs-Info none
+sub _set_shared_storage {
+    my ($self, $storage) = @_;
+    $self->{'_shared_storage'} = $storage;
+    return;
+}
+
 # Internal sub for dumping the memory usage of this instance
 #
 # Used by the frontend (under debug level >= 4)
diff --git a/lib/Lintian/Collect/Binary.pm b/lib/Lintian/Collect/Binary.pm
index 5d8cd81..cced5ef 100644
--- a/lib/Lintian/Collect/Binary.pm
+++ b/lib/Lintian/Collect/Binary.pm
@@ -29,7 +29,7 @@ use Lintian::Relation;
 use Carp qw(croak);
 use Parse::DebianChangelog;
 
-use Lintian::Util qw(fail open_gz parse_dpkg_control);
+use Lintian::Util qw(fail open_gz parse_dpkg_control get_file_checksum);
 
 =head1 NAME
 
@@ -129,8 +129,20 @@ sub changelog {
     if (-l $dch || !-f $dch) {
         $self->{changelog} = undef;
     } else {
-        my %opts = (infile => $dch, quiet => 1);
-        $self->{changelog} = Parse::DebianChangelog->init(\%opts);
+        my $shared = $self->{'_shared_storage'};
+        my ($checksum, $changelog);
+        if (defined($shared)) {
+            $checksum = get_file_checksum('sha1', $dch);
+            $changelog = $shared->{'changelog'}{$checksum};
+        }
+        if (not $changelog) {
+            my %opts = (infile => $dch, quiet => 1);
+            $changelog = Parse::DebianChangelog->init(\%opts);
+            if (defined($shared)) {
+                $shared->{'changelog'}{$checksum} = $changelog;
+            }
+        }
+        $self->{changelog} = $changelog;
     }
     return $self->{changelog};
 }
diff --git a/lib/Lintian/Collect/Group.pm b/lib/Lintian/Collect/Group.pm
index 984413f..d9c264a 100644
--- a/lib/Lintian/Collect/Group.pm
+++ b/lib/Lintian/Collect/Group.pm
@@ -23,8 +23,6 @@ package Lintian::Collect::Group;
 use strict;
 use warnings;
 
-use Carp qw(croak);
-
 =head1 NAME
 
 Lintian::Collect::Group - Lintian interface to group data collection
@@ -61,8 +59,15 @@ L<$group|Lintian::ProcessableGroup>.
 
 sub new {
     my ($class, $group) = @_;
-    my $self = {'group' => $group,};
-    return bless $self, $class;
+    my $shared_storage = {};
+    my $self = {
+        'group' => $group,
+        '_shared_storage' => $shared_storage,
+    };
+    for my $member ($group->get_processables) {
+        $member->info->_set_shared_storage($shared_storage);
+    }
+    return bless($self, $class);
 }
 
 =item direct_dependencies (PROC)
diff --git a/lib/Lintian/Collect/Source.pm b/lib/Lintian/Collect/Source.pm
index dbf0265..5d534d8 100644
--- a/lib/Lintian/Collect/Source.pm
+++ b/lib/Lintian/Collect/Source.pm
@@ -29,7 +29,7 @@ use Scalar::Util qw(blessed);
 use Lintian::Relation;
 use Parse::DebianChangelog;
 
-use Lintian::Util qw(read_dpkg_control $PKGNAME_REGEX);
+use Lintian::Util qw(get_file_checksum read_dpkg_control $PKGNAME_REGEX);
 
 =head1 NAME
 
@@ -101,8 +101,20 @@ sub changelog {
     return $self->{changelog} if exists $self->{changelog};
     my $dch = $self->index_resolved_path('debian/changelog');
     if ($dch and $dch->is_open_ok) {
-        my %opts = (infile => $dch->fs_path, quiet => 1);
-        $self->{changelog} = Parse::DebianChangelog->init(\%opts);
+        my $shared = $self->{'_shared_storage'};
+        my ($checksum, $changelog);
+        if (defined($shared)) {
+            $checksum = get_file_checksum('sha1', $dch->fs_path);
+            $changelog = $shared->{'changelog'}{$checksum};
+        }
+        if (not $changelog) {
+            my %opts = (infile => $dch->fs_path, quiet => 1);
+            $changelog = Parse::DebianChangelog->init(\%opts);
+            if (defined($shared)) {
+                $shared->{'changelog'}{$checksum} = $changelog;
+            }
+        }
+        $self->{changelog} = $changelog;
     } else {
         $self->{changelog} = undef;
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git


Reply to: