
03.12.19 20:51, Brett Cannon пише:
On Tue, Dec 3, 2019 at 2:00 AM Serhiy Storchaka <storchaka@gmail.com <mailto:storchaka@gmail.com>> wrote:
[SNIP] > ## What about performance?
It should be mentioned in the PEP that `dict1 | dict2 | dict3` is less efficient than `{**dict1, **dict2, **dict3}`.
... in CPython, but is it guaranteed to be faster in e.g. PyPy? We should be very careful about making any performance promises/points unless we know it is fairly universal that the design will explicitly make something faster or slower relative to another operation.
Does PyPy have optimizations for `list1 + list2 + list3` and `set1 | set2 | set3`? If no, it is unlikely it will have an optimization for `dict1 | dict2 | dict3`. In any case `{**dict1, **dict2, **dict3}` is optimal independently of the implementation.
To me this PEP is entirely a question of whether the operators will increase developer productivity and not some way to do dict merging faster, and so performance questions should stay out of it unless it's somehow slower than dict.update().
The PEP should contain all objections and pitfalls. I do not say that this is an argument against | for dicts, but this detail should be mentioned. BTW the PEP contains the wrong statement about `{**dict1, **dict2}` -- it works not only for string keys. After removing the false statement and adding the performance note the alternative will look much better.