A few years ago at work, I had to optimise the running time of a CGI script that is part of a bigger reporting system. The program architecture is a bit strange; in this case, the problem was accessing inherited package variables (yes, this is a thing). The class hierarchy is only three levels deep, but the variables in the leaf class get millions of accesses in a script run and many of them come from the parent or grandparent class. The variables were accessed using inherited methods.

Instead of redesigning the architecture (which is still on the todo list), I wrote a subroutine that takes a list of variable names as input (like '%FOO', '$BAR'), traverses @ISA breadth first and inspects the symbol table of each package it encounters. If it finds a typeglob with the right name and a slot of the right type, the sub imports that slot into the calling package. Of course, the subroutine checks the symbol table of the calling package for %FOO and $BAR before the expensive lookup.

I guess it's more about working around a suboptimal software architecture, but you couldn't solve it like this in certain other programming languages.


In reply to Re: RFC: Perl Second-Best Practices by vrk
in thread RFC: Perl Second-Best Practices by dimar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.