One big issue with the current ObjectSpace is the HashSet used to hold all those WeakRefs. So each object that's created gets a WeakRef added to the hashset. When the object is collected, the WeakRef is added to the ReferenceQueue. On each call to add (whenever a new object is created), cleanup is invoked, which goes through all instances in the ReferenceQueue and removes them from the HashSet.
So there's a few problems with this:
- hashing is reasonably expensive
- the HashSet will grow to hold the max number of objects and then stay that big
So perhaps there's an easy way to solve both issues. Make a new type that's both WeakRef and linked-list node.
So WeakRef is allocated on object creation, and it's added to the tail of the list. When the object is collected, WeakRef is added to the ReferenceQueue. On each call to add, cleanup is invoked, and each WeakRef is removed from the linked list. Both operations (insert and remove) should be O(1) and there won't be any hash to allocate (or keep in memory). I would wager this would be cheaper than maintaining a HashSet and certainly less memory-intensive. The "set" part of the HashSet contract is also not necessary; it's only being used for the "hash" bit, to allow removing WeakRefs that have been collected.
I'll try to mock this up, but anyone reading email before I send the impl might offer comments.
On 7/8/06, Charles O Nutter <
[EMAIL PROTECTED]> wrote:
I gave this impl a shot and it didn't speed up what I was testing, gem's generation of ri and rdoc for rake. That's not to say it isn't faster, but it seemed to be a tad slower in this one instance. It could use more testing though...it seems like it oughta be faster.
One question: It seems that it will grow to the maximum number of live objects and stay that size. I think this was an issue in the old one too. Thoughts?
--
Charles Oliver Nutter @ headius.blogspot.com
JRuby Developer @ www.jruby.org
Application Architect @ www.ventera.com
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ Jruby-devel mailing list Jruby-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jruby-devel