On Saturday 17 September 2005 02:32, Alec Warner wrote:
> Jason Stubbs wrote:
> > On Saturday 17 September 2005 01:59, Paul Varner wrote:
> >>http://bugs.gentoo.org/show_bug.cgi?id=90680
> >>
> >>Author: Paul Varner
> >>
> >>The current implementation of gentoolkit creates a portage.config
> >> object for every package object that it creates. While this is the
> >> correct thing to do from an object-oriented programming point of
> >> view, this implementation consumes an excessive amount of memory and
> >> CPU.  The proposed patch changes the portage.config object for each
> >> package object to point to a single global object.
> >>
> >>If no one sees any serious issues with the patch, I will be placing
> >> it into gentoolkit.
> >
> > I tried doing this once before locally, but found some issue with it.
> > Unfortunately, I can't remember what that issue was. If you are
> > calling setcpv() for every call to the package object that utilizes
> > the config object and no utilizing packages (in gentoolkit or
> > otherwise) are utilizing threading, it should theoretically be okay.
> > Actually, I think it was the threading issue that delayed the fix.
>
> I can't remember the model for this, but there is some logic along the
> lines of intercepting config object writes with setattr and then
> cloning the config object.  That way if the config is read-only only 1
> is instantiated, but if you attempt to modify it, the config would
> clone itself, then proceed with the modification and return the cloned
> copy. Not sure how easy that would be to implement, perhaps some sort
> of wrapper class?

To share such an object the right way from an OO perspective would require 
to pass the object along at package object instanciation. I doubt though 
that the config object should be modified. But if it must in some cases a 
lazy copy scheme is probably most efficient. You'd probably have the 
editing code do something like:
this->editableConfig()->changeAttribute(...)

Where the editableConfig function checks whether a copy has been made, if 
so, it will just use that copy, else it will make a copy and return it.

Paul


-- 
Paul de Vrieze
Gentoo Developer
Mail: [EMAIL PROTECTED]
Homepage: http://www.devrieze.net

Attachment: pgpDlxwohvwF2.pgp
Description: PGP signature

Reply via email to