[issue23282] Slightly faster set lookup

2015-01-25 Thread Raymond Hettinger
Raymond Hettinger added the comment: I had intentionally moved the entry-key == key test to be after the hash test. Unlike dicts where exact key matches are norm, sets are used for deduping (cased where keys are equal but not dups). By moving the test inside the entry-key == hash test, we

[issue23282] Slightly faster set lookup

2015-01-25 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: What about just removing the dummy test inside the hash test? The benefit is smaller but statistically sygnificant and always positive. $ ./python -m timeit -s a = list(range(10**6)); s1 = set(a); s2 = set(a) -- s1 = s2 Unpatched: 10 loops, best of 3: 39.3

[issue23282] Slightly faster set lookup

2015-01-23 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Good point Josh. Yes, it may slow down other cases, and there is a difference between sets and dicts. 1. If the key is not contained in the set, then if the first tested entry table[hash mask] is empty, then the lookup is slowed down by one pointer

[issue23282] Slightly faster set lookup

2015-01-23 Thread Josh Rosenberg
Josh Rosenberg added the comment: Does it slow down other cases? Seems to me like dictionaries would have more existing key lookups than sets to justify the optimization, since they're used for attribute lookup and the like, and because you usually want the value associated with existing

[issue23282] Slightly faster set lookup

2015-01-22 Thread Raymond Hettinger
Changes by Raymond Hettinger raymond.hettin...@gmail.com: -- assignee: - rhettinger ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue23282 ___ ___

[issue23282] Slightly faster set lookup

2015-01-20 Thread Serhiy Storchaka
New submission from Serhiy Storchaka: Currently set_lookkey() first tests entry-key == NULL, then entry-hash == hash and entry-key != dummy, and only after that entry-key == key. Proposed patch optimizes the order of comparisons. entry-key == key is tested first as for dicts. And no need to