[Freeipa-devel] [PATCH] 1 Do lazy initializiation ipalib

Alexander Bokovoy abokovoy at redhat.com
Mon Oct 31 13:22:40 UTC 2011


On Mon, 31 Oct 2011, Simo Sorce wrote:
> On Mon, 2011-10-31 at 14:19 +0200, Alexander Bokovoy wrote:
> > On Mon, 31 Oct 2011, Jan Cholasta wrote:
> > > Added finalization for __call__ and the check for CLI. Patch attached.
> > ACK from my side but see below.
> > 
> > > +    def __getattribute__(self, name):
> > > +        if not name.startswith('_Plugin__') and not name.startswith('_ReadOnly__') and name != 'finalize_late':
> > > +            self.finalize_late()
> > > +        return object.__getattribute__(self, name)
> > Could you get faster than three string comparisons? As 
> > __getattribute__ is fairly often called it would make sense to keep 
> > these operations to absolute minimum.
> 
> How common it is for name to match the above expressions ?
> If they always match then yes, we have an issue with the full strings
> being compared fully each time. If they seldom match and the name
> normally differ from the very first characters then these string
> comparisons would be really quick and not too worrying.
This is Plugin class, i.e. every instance of Command and Object.

Look at 'not name.startswith() and' clause -- it forces for each non 
_Plugin__/_ReadOnly__ prefixed attribute (i.e. all attributes added to 
HasParam, Command, Object, and their derivatives) to go through three 
comparisons before getting to the actual attribute fetching -- it means on every 
access to Object.foo, for example.

-- 
/ Alexander Bokovoy




More information about the Freeipa-devel mailing list