Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: how to improve the performance of a perl program

by BrowserUk (Patriarch)
on Aug 05, 2013 at 17:03 UTC ( [id://1047936]=note: print w/replies, xml ) Need Help??


in reply to how to improve the performance of a perl program

I have come to know about Devel::NYFTProf but not quite able to understand how to use it. The gui has a launching script which in turn calls some more scripts using some modules.

What do you not understand about how to use it?

You probably don't need to profile the gui itself, so how are you "calling" the other scripts from it?

Use faster accessors

The fastest accessor is the one you don't call.

It may go against OO-dogma; but in 95% of cases, there is no good reason to use subroutines to access instance variables from within that class's methods.

There are three main reasons formally cited for using accessors within a class's methods:

  1. To isolate the rest of that implementation from future substantial changes to the structure and/or layout of the instance data.

    This could only ever become a saving if that data layout changed beyond recognition; and if that happens, the likelihood that you would get away with not also substantially rewriting method code is almost nil.

  2. To provide centralised, single point validation of values assigned to instance variables.

    If your class is even vaguely well designed and written; it should not be possible for internally sourced assignments to instance variables to assign invalid values. Thus, re-validating those internally-sourced values for every assignment is pure overhead.

  3. People often respond to that with: "But what about values that come into a class from outside"?

    And the answer is that external inputs should be validated at the point of transition across the class boundary. Ie. Whenever an externally visible method is called; you should validate its parameters. But external code should never be directly accessing instance data, therefore there should be no such thing as externally visible accessors.

In short. External code calls methods to perform services, not access internal data. Where service methods accept arguments; those arguments must be validated immediately; and once so validated; any values derived from those arguments that subsequently gets set into instance variables require no further validation.

Thus, method code can safely directly access instance variables. Which in turn avoids both the overhead of accessor method calls; and centralised re-validation.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: how to improve the performance of a perl program

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1047936]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found