Page 1 of 1

Huge stacks / lazy loading

Posted: Tue Feb 10, 2009 11:52 pm
by josh
My data mappers / models are quite cyclic, I handle it by inserting a ghost model into the identity map, then when I "come back around" I load the object fully ( to prevent cyclic overflows ). My exception's stack traces are starting to get over 100 calls "deep", I even had to disable xdebug because it was crashing it ( tried increasing the setting ). Ran into same issue with Magento. Thing is Magento's load times were 5+ seconds per page, I'm happy performance wise, I obviously could improve but pages are well under a second. My question is not related to performance though, my question is: is having deep stack traces like this "bad practice", I mean it does make it less uncomfortable to debug at first but are there other down sides? As long as my machine has memory will my script keep running even if I make these deep call stacks? I plan to implement lazy loading down the road but for now I'm happy and don't want to be debugging ripple loading ( which could be worse ).

Any feedback from anyone who's gone down a similar route?

Re: Huge stacks / lazy loading

Posted: Wed Feb 11, 2009 5:08 pm
by alex.barylski
My first is, can you explain a little more by what you mean as cyclic? Why are they cyclic, what kind of automagic stuff do your models perform?
is having deep stack traces like this "bad practice",
Deep anything is typically bad practice...deep file structures...deep inheritence hierarchies...deep conditionals, etc...

Anytime you have to remember state, you need to become more like a computer and less like a human...

I'm curious though, maybe your cyclic models serve a greater purpose and the advantages out-weigh the negatives...but I'm not sure what you mean by cyclic.

Can you offer a quick and dirty example?

Re: Huge stacks / lazy loading

Posted: Thu Feb 12, 2009 6:17 am
by josh
Well I'm talking about simply a large graph of objects that results in large call stacks, I don't have any of the other "deep" things you mentioned.
Martin Fowler wrote:The problem with a rich constructor is that you have to be aware of cyclic references. If you have 2 objects that reference each other, each time you try to load one it will try to load the other, which will in turn try to load the first one, and so on, until you run out of stack space. Avoiding this requires special case code, often using Lazy Load, writing this special case code is messy so its worth trying to do without it. You can do this by creating an empty object using a no arg constructor to create a blank object and insert that object immediately into the identity map
As mentioned I'm ghosting the objects to avoid fully recursive loading, but I have not implemented true lazy loading yet. Its on my list to do but at the same time I'm developing an application not a framework so it would be premature optimization for now, I think... Especially since it would slow down development for me to sit there and debug ripple loads which could potentially be a lot slower than simply aggressively loading. I could also introduce specialized finders that limit what gets pulled back in each go I guess. As mentioned I'm able to debug it no problem, when I get a 120 line call stack I simply ignore the first 115 calls or so since they all executed fine ;-) My biggest question is as to whether the platform is going to start misbehaving on me one day. This is only happening inside my data mapper.