This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Tighten-up search loops in sets
Type: performance Stage:
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: pitrou, python-dev, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-12-24 05:52 by rhettinger, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tight0.diff rhettinger, 2014-12-24 05:52 Tighten-up search loops. review
time_tight.py rhettinger, 2014-12-24 05:53 Simple timings
tight_insert.diff rhettinger, 2014-12-26 17:43 Hoist dummy check outside of the insertion loop in resize review
set_fill_to_used.diff rhettinger, 2014-12-26 22:17 Minor improvement -- switch loop count from fill to used review
Messages (4)
msg233073 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-12-24 05:52
The lookkey functions currently check for an exact key match in the inner search-loop.  Move that test to occur after a matching hash is found rather than testing every entry.  This gives a modest speed improvement.

--- n = 10,000 ---
$ ~/baseline/python.exe -m timeit -s 'from time_tight import s,t,u' 's&t'
1000 loops, best of 3: 396 usec per loop
$ ~/tight/python.exe -m timeit -s 'from time_tight import s,t,u' 's&t'
1000 loops, best of 3: 367 usec per loop
$ ~/tight/python.exe -m timeit -s 'from time_tight import s,t,u' 's&t'
1000 loops, best of 3: 375 usec per loop
$ ~/baseline/python.exe -m timeit -s 'from time_tight import s,t,u' 's&t'
1000 loops, best of 3: 389 usec per loop
$ 
$ ~/baseline/python.exe -m timeit -s 'from time_tight import s,t,u' 's&u'
1000 loops, best of 3: 656 usec per loop
$ ~/tight/python.exe -m timeit -s 'from time_tight import s,t,u' 's&u'
1000 loops, best of 3: 657 usec per loop
$ ~/baseline/python.exe -m timeit -s 'from time_tight import s,t,u' 's&u'
1000 loops, best of 3: 662 usec per loop
$ ~/tight/python.exe -m timeit -s 'from time_tight import s,t,u' 's&u'
1000 loops, best of 3: 642 usec per loop

-- n = 1,000,000 --
$ ~/baseline/python.exe -m timeit -s 'from time_tight import s,t,u' 's&t'
10 loops, best of 3: 67 msec per loop
$ ~/tight/python.exe -m timeit -s 'from time_tight import s,t,u' 's&t'
10 loops, best of 3: 48.2 msec per loop
$ ~/baseline/python.exe -m timeit -s 'from time_tight import s,t,u' 's&t'
10 loops, best of 3: 59.9 msec per loop
$ ~/tight/python.exe -m timeit -s 'from time_tight import s,t,u' 's&t'
10 loops, best of 3: 49.1 msec per loop
 
$ ~/baseline/python.exe -m timeit -s 'from time_tight import s,t,u' 's&u'
10 loops, best of 3: 173 msec per loop
$ ~/tight/python.exe -m timeit -s 'from time_tight import s,t,u' 's&u'
10 loops, best of 3: 152 msec per loop
$ ~/baseline/python.exe -m timeit -s 'from time_tight import s,t,u' 's&u'
10 loops, best of 3: 170 msec per loop
$ ~/tight/python.exe -m timeit -s 'from time_tight import s,t,u' 's&u'
10 loops, best of 3: 167 msec per loop
msg233115 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-12-26 19:59
The patches are orthogonal, right? Both patches look ok to me.
msg233120 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-12-26 22:17
One more small orthogonal patch:  in the presence of dummy entries, it is a bit cheaper to count filled entries than used entries.
msg233125 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-12-27 04:14
New changeset c15f8debd6c9 by Raymond Hettinger in branch 'default':
Issue #23107:  Tighten-up loops in setobject.c
https://hg.python.org/cpython/rev/c15f8debd6c9
History
Date User Action Args
2022-04-11 14:58:11adminsetgithub: 67296
2014-12-27 08:36:51rhettingersetstatus: open -> closed
resolution: fixed
2014-12-27 04:14:13python-devsetnosy: + python-dev
messages: + msg233125
2014-12-26 22:17:53rhettingersetfiles: + set_fill_to_used.diff

messages: + msg233120
2014-12-26 19:59:29pitrousetmessages: + msg233115
2014-12-26 17:43:57rhettingersetfiles: + tight_insert.diff
2014-12-25 23:03:27vstinnersetnosy: + pitrou, serhiy.storchaka
2014-12-24 05:53:04rhettingersetfiles: + time_tight.py
2014-12-24 05:52:12rhettingercreate