[issue31179] Speed-up dict.copy() up to 5.5 times.

2018-01-22 Thread Yury Selivanov
Change by Yury Selivanov : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___ ___

[issue31179] Speed-up dict.copy() up to 5.5 times.

2018-01-22 Thread Yury Selivanov
Yury Selivanov added the comment: New changeset b0a7a037b8fde56b62f886d5188bced7776777b4 by Yury Selivanov in branch 'master': bpo-31179: Make dict.copy() up to 5.5 times faster. (#3067) https://github.com/python/cpython/commit/b0a7a037b8fde56b62f886d5188bced7776777b4 -- ___

[issue31179] Speed-up dict.copy() up to 5.5 times.

2018-01-22 Thread Yury Selivanov
Yury Selivanov added the comment: Victor: done; https://bugs.python.org/issue32623 -- ___ Python tracker ___ ___ Python-bugs-list ma

[issue31179] Speed-up dict.copy() up to 5.5 times.

2018-01-22 Thread STINNER Victor
STINNER Victor added the comment: Yury: Would you mind to open an issue to investigate why dict are not compatected automatically? -- ___ Python tracker ___ __

[issue31179] Speed-up dict.copy() up to 5.5 times.

2018-01-21 Thread Yury Selivanov
Yury Selivanov added the comment: I've pushed a new version of the patch that I intend to merge tomorrow. The last version has only one minor change: it uses fast-path for "slightly" non-compact dicts too (dicts don't use *at most* 3 entries). This protects us from pathological cases when a

[issue31179] Speed-up dict.copy() up to 5.5 times.

2017-08-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The side effect of this patch is making dict.copy() atomic. This is a worthy feature if extent it to dict constructor. For now the only way of making an atomic (or almost atomic) copy of a dict is dict(list(d.itemview())). It isn't very time and memory effic

[issue31179] Speed-up dict.copy() up to 5.5 times.

2017-08-11 Thread Yury Selivanov
Yury Selivanov added the comment: > I like idea. > One worrying point is how to deal with dirty dict. > How about do it only when ma_used == keys->dk_nentries? I've added this check. See the updated PR. > The PR changes the behavior. Currently the effect of copying is compacting > the dict.

[issue31179] Speed-up dict.copy() up to 5.5 times.

2017-08-11 Thread Yury Selivanov
Yury Selivanov added the comment: > Why "del" doesn't compact the dict? This is a good question, btw. -- ___ Python tracker ___ ___ P

[issue31179] Speed-up dict.copy() up to 5.5 times.

2017-08-11 Thread STINNER Victor
STINNER Victor added the comment: d = dict.fromkeys(range(2000)) for i in range(1999): del d[i] > ... sys.getsizeof(d) > 41020 sys.getsizeof(d.copy()) > 136 Why "del" doesn't compact the dict? -- ___ Python tracker

[issue31179] Speed-up dict.copy() up to 5.5 times.

2017-08-11 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- nosy: +rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail

[issue31179] Speed-up dict.copy() up to 5.5 times.

2017-08-11 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The PR adds over 50 lines of code for optimising not very often used feature. There are two obvious ways of copying, dict(d) and d.copy(), the PR optimises just the latter one, and I'm not sure this is the most used way. The PR duplicates the low-level code,

[issue31179] Speed-up dict.copy() up to 5.5 times.

2017-08-10 Thread INADA Naoki
INADA Naoki added the comment: I like idea. One worrying point is how to deal with dirty dict. How about do it only when ma_used == keys->dk_nentries? Slightly off topic. Copy on write can be implemented via dk_refcnt. Functions just passing `**kwargs` has temporal copy of dict. And CoW will red

[issue31179] Speed-up dict.copy() up to 5.5 times.

2017-08-10 Thread Yury Selivanov
Yury Selivanov added the comment: >> PyDict_Copy creates a new empty dict object and then inserts key/values into >> it one by one. > Why not creating a "preallocated" dict in that case? _PyDict_NewPresized() I don't think it's related to the proposed patch. Please take a look at the PR. `_

[issue31179] Speed-up dict.copy() up to 5.5 times.

2017-08-10 Thread STINNER Victor
STINNER Victor added the comment: > PyDict_Copy creates a new empty dict object and then inserts key/values into > it one by one. Why not creating a "preallocated" dict in that case? _PyDict_NewPresized() -- ___ Python tracker

[issue31179] Speed-up dict.copy() up to 5.5 times.

2017-08-10 Thread Yury Selivanov
New submission from Yury Selivanov: It's possible to significantly improve performance of shallow dict copy. Currently, PyDict_Copy creates a new empty dict object and then inserts key/values into it one by one. My idea is to simply memcpy the whole keys/items region and do the necessary inc

[issue31179] Speed-up dict.copy() up to 5.5 times.

2017-08-10 Thread Yury Selivanov
Changes by Yury Selivanov : -- pull_requests: +3104 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mai