Posted on 2009-01-11 16:47:08-08 by jerome in response to 9675
Re: Generating thousands of objects
Jerry, I have been thinking some more about the requirements for my project and I sure would like to be able to use Object::InsideOut for my short lived classes. I still need encapsulation and inheritance for example. So I spent more time with NYTProf and Object::InsideOut and would like to submit to you that the current sluggishness of OIO on object creation/deletion isn't necessarily a fact of life for some situations (like mine for example).

1. A large amount of time is spent in '_ID'. This may not be necessary when the users will only ever need one instance of the class at a time (as is my case). I suggest that OIO supports an additional class attribute on top of :public, :private, etc.. called something like ':singleton' to signal that particular usage of the class. Bypassing _ID improved object creation/deletion performance by 70% in my, albeit very simplistic, benchmark.

2. Most of the time left during 'new' is spent figuring out that nothings needs to be done. This is done for each object. I suggest that OIO supports another class attribute called ':inline' for example (and maybe a class method 'inline' also) that would radically change what happens during 'new'. Instead of checking every time what needs to be done, the 'new' subroutine would generate, stash and run a subroutine containing the minimum amount of code required for generating an object of the class. Such subroutine could be invalidated and regenerated if the user alters the class at runtime (by calling 'create_field' or 'add_class' for example). The user would incur a higher cost for the first object created for the class but additional objects may be much faster to generate (especially if their class is fairly simple) with no loss of functionality.

Does that sound right to you? Jerome
Direct Responses: 9708 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.