Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2011/11/10

Beyond Firebug to NYTProf

Clearly, the problem is in the core application, not the CSS and JS surrounding it. And Firebug only covers the outside of the application.

So I got NYTProf going. A little search gave me the knowledge that calling a page at http://example.com/myprog.cgi?foo=bar is the same as calling it with perl myprog.cgi 'foo=bar', which is so good to know, especially since the addition of the NYTProf step is perl -d:NYTProf myprog.cgi 'foo=bar' .

So, I was able to shave off a second by caching. I could have HOP'd it and just used Memoize, but I like having all the details of a program visible so I don't get bit by something I can't see.

  1. {  
  2.     # all lines of code with  %url_cache are new  
  3.     # URLs have been changed to protect the innocent.  
  4.     my %url_cache ;  
  5.     sub get_service_page {  
  6.         my ( $pi ) = @_ ;  
  7.         if ( $url_cache$pi } ) {  
  8.             return $url_cache$pi } ;  
  9.             }  
  10.         my $readfile = pi_Readfile() ;  
  11.         my $url = 'http://www.example.edu/~user/projects/XXXXX/' ;  
  12.         my $alt =  
  13.             'http://www.example.edu/~user/something_else.cgi'  
  14.             ;  
  15.         my $attr   = 'SGNAME_PUTATIVE' ;  
  16.         my $sgname = $readfile->{ $pi }->{ $attr } ;  
  17.   
  18.         if ( ! defined $sgname || '' eq $sgname ) {  
  19.             $url_cache$pi } = $alt ;  
  20.             return $alt ;  
  21.             }  
  22.         $url =~ s/XXXXX/$sgname/ ;  
  23.         $url_cache$pi } = $url ;  
  24.         return $url ;  
  25.         }  
  26.     }  

So, simply by holding onto that little piece of information instead of checking against the same pi_Readfile() each time, I was able to go from 2-3 seconds to 1.2 seconds. And, now that I'm seeing it, I could hold onto the data structure I get from  pi_Readfile() the same way I hold onto the cache, and could probably tighten up even more.

I don't know why it didn't occur to me to do that in the first place....

No comments:

Post a Comment