[issue16562] Optimize dict equality test

2012-12-02 Thread Roundup Robot

Roundup Robot added the comment:

New changeset d12785ecca72 by Antoine Pitrou in branch 'default':
Issue #16562: Optimize dict equality testing.
http://hg.python.org/cpython/rev/d12785ecca72

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16562
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16562] Optimize dict equality test

2012-12-02 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 The patch looks correct.  If the tests pass, go ahead and apply it.

Done.

--
nosy: +pitrou
resolution:  - fixed
stage: patch review - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16562
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16562] Optimize dict equality test

2012-11-27 Thread Martin v . Löwis

Martin v. Löwis added the comment:

The patch looks good to me.

--
nosy: +loewis

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16562
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16562] Optimize dict equality test

2012-11-27 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

And here is a synthetic microbenchmark:

$ ./python -m timeit -s n=10**3; k=2; a={(i,)*k:i for i in range(n)}; 
b={(i,)*k:i for i in range(n)}  a == b

Vanilla: 251 usec per loop
Patched: 195 usec per loop

$ ./python -m timeit -s n=10**3; k=2; a={(i,)*k:i for i in range(n)}; 
b=dict(a)  a == b

Vanilla: 116 usec per loop
Patched: 58.6 usec per loop

The use of tuple keys is quite common.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16562
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16562] Optimize dict equality test

2012-11-27 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@gmail.com:


--
nosy: +haypo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16562
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16562] Optimize dict equality test

2012-11-27 Thread Raymond Hettinger

Raymond Hettinger added the comment:

The patch looks correct.  If the tests pass, go ahead and apply it.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16562
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16562] Optimize dict equality test

2012-11-26 Thread Raymond Hettinger

New submission from Raymond Hettinger:

The code for dict_equal() in Objects/dictobject.c currently loops over the 
key/value pairs in self and uses PyDict_GetItem() to check for the 
corresponding key/value pair in the other dictionary.  This causes an 
unnecessary call to PyObject_Hash().

Instead, the code should loop over the key/value/hash triplets in self and do a 
direct lookup in the other dictionary with  ep = 
(otherdict-ma_lookup)(otherdict, key, hash).   The reuses the known hash 
value for the key; thereby avoiding the potentially slow call to 
PyObject_Hash().

See _PyDict_Contains() for an example of how to do a lookup when the hash value 
is already known.

Note, the optimized path should be used only when PyDict_CheckExact() is true.

--
components: Interpreter Core
keywords: easy
messages: 176453
nosy: rhettinger
priority: low
severity: normal
status: open
title: Optimize dict equality test
type: performance
versions: Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16562
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16562] Optimize dict equality test

2012-11-26 Thread Jesús Cea Avión

Changes by Jesús Cea Avión j...@jcea.es:


--
nosy: +jcea

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16562
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16562] Optimize dict equality test

2012-11-26 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Here is a simple patch.

 Note, the optimized path should be used only when PyDict_CheckExact() is true.

Actually this is not needed. dict_equal() uses the same code for dict 
subclasses.

--
keywords: +patch
nosy: +serhiy.storchaka
stage:  - patch review
Added file: http://bugs.python.org/file28137/dict_equal_hash_reuse.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16562
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com