Message279497
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 |
|
Date |
User |
Action |
Args |
2016-10-26 10:08:44 | methane | set | recipients:
+ methane, rhettinger, benjamin.peterson, Mark.Shannon, serhiy.storchaka, xiang.zhang |
2016-10-26 10:08:44 | methane | set | messageid: <1477476524.87.0.23485828872.issue28509@psf.upfronthosting.co.za> |
2016-10-26 10:08:44 | methane | link | issue28509 messages |
2016-10-26 10:08:44 | methane | create | |
|