Rev 163: Some small changes. in http://bazaar.launchpad.net/~meliae-dev/meliae/trunk
John Arbash Meinel
john at arbash-meinel.com
Thu Jul 29 15:37:49 BST 2010
At http://bazaar.launchpad.net/~meliae-dev/meliae/trunk
------------------------------------------------------------
revno: 163
revision-id: john at arbash-meinel.com-20100729143729-glo62wr5im8e1ggf
parent: john at arbash-meinel.com-20100728211306-czkdksnp4am5ljii
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: trunk
timestamp: Thu 2010-07-29 09:37:29 -0500
message:
Some small changes.
Make it a bit easier to get refs_as_dict after removing expensive refs.
Promote _compute_total_size(obj) to being the primary interface. The old
one just never worked right anyway.
-------------- next part --------------
=== modified file 'CHANGES.txt'
--- a/CHANGES.txt 2010-07-28 20:36:40 +0000
+++ b/CHANGES.txt 2010-07-29 14:37:29 +0000
@@ -13,6 +13,11 @@
* Add ``__sizeof__`` members to a lot of the core classes (IntSet,
etc.) (John Arbash Meinel)
+* ``ObjectManager.compute_total_size()`` now only computes the size of
+ a single object, rather than all objects. All objects took too long
+ to be useful anyway, better to make it easier to use the useful api.
+ (John Arbash Meinel)
+
Meliae 0.2.1
############
=== modified file 'meliae/_loader.pyx'
--- a/meliae/_loader.pyx 2010-07-28 21:13:06 +0000
+++ b/meliae/_loader.pyx 2010-07-29 14:37:29 +0000
@@ -584,8 +584,9 @@
"""
as_dict = {}
children = self.children
- if self.type_str not in ('dict', 'module'):
- # Instance dicts end with a 'type' reference
+ if len(children) % 2 == 1 and self.type_str not in ('dict', 'module'):
+ # Instance dicts end with a 'type' reference, but only do that if
+ # we actually have an odd number
children = children[:-1]
for idx in xrange(0, len(children), 2):
key = self.collection[children[idx]]
=== modified file 'meliae/loader.py'
--- a/meliae/loader.py 2010-07-16 15:38:56 +0000
+++ b/meliae/loader.py 2010-07-29 14:37:29 +0000
@@ -314,7 +314,8 @@
self.show_progress):
continue
- def _compute_total_size(self, obj):
+ def compute_total_size(self, obj):
+ """Sum the size of all referenced objects (recursively)."""
pending_descendents = list(obj.children)
seen = _intset.IDSet()
seen.add(obj.address)
@@ -341,32 +342,6 @@
obj.total_size = total_size
return obj
- def compute_total_size(self):
- """This computes the total bytes referenced from this object."""
- # Unfortunately, this is an N^2 operation :(. The problem is that
- # a.total_size + b.total_size != c.total_size (if c references a & b).
- # This is because a & b may refer to common objects. Consider something
- # like:
- # A _
- # / \ / \
- # B C |
- # \ / /
- # D--'
- # D & C participate in a refcycle, and B has an alternative path to D.
- # You certainly don't want to count D 2 times when computing the total
- # size of A. Also, how do you give the relative contribution of B vs C
- # in this graph?
- total = len(self.objs)
- break_on = total / 10
- for idx, obj in enumerate(self.objs.itervalues()):
- if self.show_progress and idx & 0x1ff == 0:
- sys.stderr.write('compute size %8d / %8d \r'
- % (idx, total))
- self._compute_total_size(obj)
- if self.show_progress:
- sys.stderr.write('compute size %8d / %8d \n'
- % (idx, total))
-
def summarize(self):
summary = _ObjSummary()
for obj in self.objs.itervalues():
More information about the bazaar-commits
mailing list