classification
Title: Apply the setobject optimizations to dictionaries
Type: performance Stage:
Components: Interpreter Core Versions: Python 3.5
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Alan.Cristhian, Mark.Shannon, eli.bendersky, eric.snow, pitrou, rhettinger, serhiy.storchaka, tim.peters, vstinner
Priority: low Keywords: patch

Created on 2013-09-01 05:14 by rhettinger, last changed 2016-01-26 03:38 by rhettinger. This issue is now closed.

Files
File name Uploaded Description Edit
noincref.diff rhettinger, 2013-09-05 08:15 First draft to eliminate incref/decref on dummy objects review
Messages (6)
msg196706 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2013-09-01 05:14
Once http://bugs.python.org/issue18835 is resolved, I would like to see the various set optimizations applied to dictionaries as well:

* Move the key before the hash in the dict struct (the key is accessed more frequently in the code and being in the first struct position allows it to be looked-up without a struct offset).

* Don't INCREF and DECREF dummy objects.  Only one reference needs to be held.  See http://bugs.python.org/issue18797

* Reduce the cost of hash collisions by inspecting nearby dict entries for matches prior to moving on to other probes elsewhere in memory.  See http://bugs.python.org/issue18771

* Make the previous improvement more effective by using aligned memory allocations for the dict tables.  See http://bugs.python.org/issue18835

Collectively, these optimizations can substantially improve dictionary performance.
msg196710 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2013-09-01 05:39
+1 This is worth trying.
msg196909 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-09-04 13:24
I'm still interested in seeing benchmarks that show where this actually improves things and by how much. Also, whether any regressions occur and how serious they are.
msg234881 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-01-28 10:14
noincref.diff doesn't contain all necessary changes. For example dummy is increfed in dict_pop() and dict_popitem() and may be decrefed at insert.

As in sets we can got rid of few comparisons with dummy if set dummy hashes to -1.
msg239382 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-03-27 08:54
Hi, what's the status of this issue? Is anyone working one it?
msg258944 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2016-01-26 03:38
> Hi, what's the status of this issue? Is anyone working one it?

In the present environment, I feel like advancing this work would be an uphill battle and that much of my time investment would be wasted unnecessarily.

That's too bad, because significant r&d time has already been invested and it has had nice payoffs with set objects.
History
Date User Action Args
2016-01-26 03:38:40rhettingersetstatus: open -> closed

messages: + msg258944
2015-03-27 08:54:17vstinnersetmessages: + msg239382
2015-01-28 10:14:02serhiy.storchakasetmessages: + msg234881
2015-01-20 08:11:10rhettingersetversions: + Python 3.5, - Python 3.4
2013-09-05 08:15:00rhettingersetfiles: + noincref.diff
keywords: + patch
2013-09-04 13:38:19pitrousetnosy: + serhiy.storchaka
2013-09-04 13:24:21eli.benderskysetnosy: + eli.bendersky
messages: + msg196909
2013-09-04 00:49:05Alan.Cristhiansetnosy: + Alan.Cristhian
2013-09-01 05:39:38eric.snowsetnosy: + Mark.Shannon, eric.snow
messages: + msg196710
2013-09-01 05:14:53rhettingercreate