From: Gustaf N. <ne...@wu...> - 2008-05-08 19:55:56
|
Donal K. Fellows schrieb: > Donal K. Fellows wrote: > >> Damon Courtney wrote: >> >>> TclOO sucks memory like a damn mind flayer (gratuitous D&D >>> reference). It uses more than Itcl, for God's sake. Remove the cruft >>> and crap and make XOTcl (a tried and tested OO extension) the core. >> >> Figuring out where it is consuming memory is something for experts; I'm >> no expert on the implementation, so all I can do is provide advice once >> someone else identifies the issue. I suspect, and this is not grounded >> in deep code inspection and so may be way off base but is founded on a >> quick scan of their implementation of [next], that the problem is the >> number of stack frames it uses. (TclOO uses a different approach that is >> much lighter weight.) Reducing the number of stack frames is *hard* >> since that's almost certainly a deeply ingrained assumption. >> > > It's been pointed out to me that Damon said TclOO was memory hungry. Oops! > donal, i am not sure wether you got it, Damon suggested to put xotcl into the core. just for a reference, comparing xotcl 1.6.0 and tcl oo 0.2 with tcl 8.5.2 using XOTcl... Used memory: 244330496 Memory per XOTcl object: 244 Time per XOTcl object: 5.01 using TclOO... Used memory: 929992704 Memory per TclOO object: 929 Time per TclOO object: 12.26 so, for the object creation test, xotcl is more the two times faster on object creation and uses more than three times less memory than tcloo. On my notebook i can easily create 5mio xotcl objects, where TclOO fails badly. The xotcl creation uses alloc, which is closer to what tcloo create does. The engineering of xotcl looks quite ok here. i am sure, TclOO should be able to beat XOTcl in this benchmark, since so many features were dropped from XOTcl. But when talking about language design, speed is just one issue. > I've a good idea where that memory consumption is coming from (probably > the per-object caches, though maybe also the fact that some structures > are allocated at object construction and not when first used) and hope > to clean that up. It won't change any API in the slightest. Without looking into the code, i have serious doubts that the above differences are due to caching, since the script below does nothing else but creating objects. But you are the expert here you called for in your reply cited above.... Since you mentioned caching: i was just interested on the effects of caching when e.g. objects are reclassed. However, i could not figure out, how objects can be reclassed in tcloo! Neither the man pages or tip 257 mention it. Dynamic reclassificaiton (sometimes called in the literature "object migration") is important for e.g. oo databases or dynamic systems. Is the documentation bad, or was dynamic reclassification silently dropped in TclOO? -gustaf neumann ################################################## package require XOTcl namespace path xotcl set n 5000000 Class Mem Mem instproc init {} { set r [exec ps -xv | fgrep [pid]] ::xotcl::my set m [lindex $r 6] } Mem m1 if {1} { set oo XOTcl puts "using $oo..." Class Foo set ts [time { for {set i 0} {$i<$n} {incr i} { Foo alloc $i }}] } else { set oo TclOO puts "using $oo..." package require TclOO namespace path oo class create foo {} set ts [time { for {set i 0} {$i<$n} {incr i} { foo create $i }}] } Mem m2 set objm [expr {([m2 set m]-[m1 set m])*1024}] set t [lindex $ts 0] puts " Used memory: $objm Memory per $oo object: [expr {$objm/$n}] Time per $oo object: [format %4.2f [expr {$t*1.0/$n}]] " |