Igor Gariev (gariev) wrote in changelog,
Igor Gariev
gariev
changelog

[livejournal] r17412: Minor optimization: some performance gai...

Committer: gariev
Minor optimization: some performance gain for entries with 5000+ comments
U   trunk/cgi-bin/LJ/Comment.pm
U   trunk/cgi-bin/LJ/Entry.pm
U   trunk/cgi-bin/LJ/Talk.pm
U   trunk/cgi-bin/LJ/User.pm
U   trunk/cgi-bin/ljlib.pl
Modified: trunk/cgi-bin/LJ/Comment.pm
===================================================================
--- trunk/cgi-bin/LJ/Comment.pm	2010-09-20 09:44:05 UTC (rev 17411)
+++ trunk/cgi-bin/LJ/Comment.pm	2010-09-20 10:21:59 UTC (rev 17412)
@@ -66,7 +66,6 @@
 # </LJFUNC>
 sub instance {
     my $class = shift;
-    my $self  = bless {};
 
     my $uuserid = shift;
     my $n_arg   = scalar @_;
@@ -75,35 +74,29 @@
 
     my %opts = @_;
 
-    $self->{journalid} = LJ::want_userid($uuserid) or
+    my $journalid = LJ::want_userid($uuserid) or
         croak("invalid journalid parameter");
 
-    $self->{jtalkid} = int(delete $opts{jtalkid});
+    my $jtalkid = int(delete $opts{jtalkid});
 
     if (my $dtalkid = int(delete $opts{dtalkid})) {
-        $self->{jtalkid} = int($dtalkid / 256);
+        $jtalkid = int($dtalkid / 256);
     }
 
     croak("need to supply jtalkid or dtalkid")
-        unless $self->{jtalkid};
+        unless $jtalkid;
 
     croak("unknown parameter: " . join(", ", keys %opts))
         if %opts;
 
-    my $journalid = $self->{journalid};
-    my $jtalkid   = $self->{jtalkid};
-
     # do we have a singleton for this comment?
-    $singletons{$journalid} ||= {};
     return $singletons{$journalid}->{$jtalkid}
         if $singletons{$journalid}->{$jtalkid};
-
-    # save the singleton if it doesn't exist
+    
+    my $self = bless { journalid => $journalid, jtalkid => $jtalkid };
+    # save the singleton 
     $singletons{$journalid}->{$jtalkid} = $self;
 
-    croak("need to supply jtalkid") unless $self->{jtalkid};
-    croak("unknown parameters: " . join(", ", keys %opts))
-        if %opts;
     return $self;
 }
 *new = \&instance;
@@ -211,9 +204,9 @@
 
 
 sub absorb_row {
-    my ($self, %row) = @_;
+    my ($self, $row) = @_;
 
-    $self->{$_} = $row{$_} foreach (qw(nodetype nodeid parenttalkid posterid datepost state));
+    $self->{$_} = $row->{$_} foreach (qw(nodetype nodeid parenttalkid posterid datepost state));
     $self->{_loaded_row} = 1;
 }
 
@@ -472,7 +465,7 @@
         next unless $row;
 
         # absorb row into the given LJ::Comment object
-        $obj->absorb_row(%$row);
+        $obj->absorb_row($row);
     }
 
     return 1;

Modified: trunk/cgi-bin/LJ/Entry.pm
===================================================================
--- trunk/cgi-bin/LJ/Entry.pm	2010-09-20 09:44:05 UTC (rev 17411)
+++ trunk/cgi-bin/LJ/Entry.pm	2010-09-20 10:21:59 UTC (rev 17412)
@@ -171,7 +171,7 @@
 
     my $journalu = LJ::load_userid($row{journalid});
     my $self = $class->new($journalu, jitemid => $row{jitemid});
-    $self->absorb_row(%row);
+    $self->absorb_row(\%row);
 
     return $self;
 }
@@ -330,14 +330,14 @@
         next unless $lg;
 
         # absorb row into given LJ::Entry object
-        $en->absorb_row(%$lg);
+        $en->absorb_row($lg);
     }
 }
 
 sub absorb_row {
-    my ($self, %row) = @_;
+    my ($self, $row) = @_;
 
-    $self->{$_} = $row{$_} foreach (qw(allowmask posterid eventtime logtime security anum));
+    $self->{$_} = $row->{$_} foreach (qw(allowmask posterid eventtime logtime security anum));
     $self->{_loaded_row} = 1;
 }
 

Modified: trunk/cgi-bin/LJ/Talk.pm
===================================================================
--- trunk/cgi-bin/LJ/Talk.pm	2010-09-20 09:44:05 UTC (rev 17411)
+++ trunk/cgi-bin/LJ/Talk.pm	2010-09-20 10:21:59 UTC (rev 17412)
@@ -742,7 +742,7 @@
 }
 
 sub get_talk_data {
-    my ($u, $nodetype, $nodeid, $opts) = @_;
+    my ($u, $nodetype, $nodeid) = @_;
     return undef unless LJ::isu($u);
     return undef unless $nodetype =~ /^\w$/;
     return undef unless $nodeid =~ /^\d+$/;
@@ -750,12 +750,12 @@
 
     # call normally if no gearman/not wanted
     my $gc = LJ::gearman_client();
-    return get_talk_data_do($uid, $nodetype, $nodeid, $opts)
+    return get_talk_data_do($uid, $nodetype, $nodeid)
         unless $gc && LJ::conf_test($LJ::LOADCOMMENTS_USING_GEARMAN, $u->id);
 
     # invoke gearman
     my $result;
-    my @a = ($uid, $nodetype, $nodeid, $opts);
+    my @a = ($uid, $nodetype, $nodeid);
     my $args = Storable::nfreeze(\@a);
     my $task = Gearman::Task->new("get_talk_data", \$args,
                                   {
@@ -779,15 +779,12 @@
 #                             'parenttalkid', 'state' } , or undef on failure
 sub get_talk_data_do
 {
-    my ($uid, $nodetype, $nodeid, $opts) = @_;
+    my ($uid, $nodetype, $nodeid) = @_;
     my $u = LJ::want_user($uid);
     return undef unless LJ::isu($u);
     return undef unless $nodetype =~ /^\w$/;
     return undef unless $nodeid =~ /^\d+$/;
 
-    my $init_comobj = 1;
-       $init_comobj = $opts->{init_comobj} if exists $opts->{init_comobj};
-
     my $ret = {};
 
     # check for data in memcache
@@ -829,8 +826,8 @@
 
     my $make_comment_singleton = sub {
         my ($jtalkid, $row) = @_;
-        return 1 unless $init_comobj;
         return 1 unless $nodetype eq 'L';
+
         # at this point we have data for this comment loaded in memory
         # -- instantiate an LJ::Comment object as a singleton and absorb
         #    that data into the object
@@ -838,7 +835,7 @@
         # add important info to row
         $row->{nodetype} = $nodetype;
         $row->{nodeid}   = $nodeid;
-        $comment->absorb_row(%$row);
+        $comment->absorb_row($row);
 
         return 1;
     };
@@ -1098,8 +1095,7 @@
     my $n = $u->{'clusterid'};
     my $viewall = $opts->{viewall};
 
-    my $gtd_opts = {init_comobj => $opts->{init_comobj}};
-    my $posts = get_talk_data($u, $nodetype, $nodeid, $gtd_opts);  # hashref, talkid -> talk2 row, or undef
+    my $posts = get_talk_data($u, $nodetype, $nodeid);  # hashref, talkid -> talk2 row, or undef
     unless ($posts) {
         $opts->{'out_error'} = "nodb";
         return;

Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm	2010-09-20 09:44:05 UTC (rev 17411)
+++ trunk/cgi-bin/LJ/User.pm	2010-09-20 10:21:59 UTC (rev 17412)
@@ -2148,7 +2148,7 @@
 
         # construct an LJ::Comment singleton
         my $comment = LJ::Comment->new($u, jtalkid => $r->{jtalkid});
-        $comment->absorb_row(%$r);
+        $comment->absorb_row($r);
         next unless $comment->visible_to($remote);
         push @recv, $r;
     }

Modified: trunk/cgi-bin/ljlib.pl
===================================================================
--- trunk/cgi-bin/ljlib.pl	2010-09-20 09:44:05 UTC (rev 17411)
+++ trunk/cgi-bin/ljlib.pl	2010-09-20 10:21:59 UTC (rev 17412)
@@ -1205,7 +1205,7 @@
 
         # construct an LJ::Entry singleton
         my $entry = LJ::Entry->new($userid, jitemid => $li->{itemid});
-        $entry->absorb_row(%$li);
+        $entry->absorb_row($li);
     }
     $flush->();
 

Tags: gariev, livejournal, pl, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments