INADA Naoki added the comment: OK, I won't change it to allow additional resize while merging, after pre-resize. But current code has two problem:
* Pre-resize happen even when resizing is not necessary. (ex. two dict has same keys). * Pre-resize allocates too much memory which doesn't make sense. Next patch (28509-smaller-update2.patch) seems better because: * When pre-resize doesn't happen, at most one resize while merging. * When pre-resize happens, no resize happens while merging. * Doesn't make surprisingly sparse dict when two dicts have same keys. PoC code: import sys b = {} for i in range(16): b[i] = i a = b.copy() a.update(b) # No need to resize print(i, sys.getsizeof(a), sys.getsizeof(b)) Current: 0 256 256 1 256 256 2 256 256 3 664 256 4 664 256 5 384 384 # !!! 6 664 384 7 664 384 8 664 384 9 664 384 10 664 664 11 664 664 12 1200 664 13 1200 664 14 1200 664 15 1200 664 With second patch: 0 256 256 1 256 256 2 256 256 3 256 256 4 256 256 5 384 384 6 384 384 7 384 384 8 384 384 9 384 384 10 664 664 11 664 664 12 664 664 13 664 664 14 664 664 15 664 664 ---------- Added file: http://bugs.python.org/file45229/28509-smaller-update2.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28509> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com