← Back to DAGDA | Support | Source: https://bugs.python.org/issue24762

➜

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: Branchless, vectorizable frozen set hash
Type: performance Stage: resolved
Components: Interpreter Core Versions: Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: python-dev, rhettinger, serhiy.storchaka
Priority: low Keywords: patch

Created on 2015-07-31 05:13 by rhettinger, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fashhash_nobranch.diff rhettinger, 2015-07-31 05:13 Patch for faster hashing review
timings_fasthash.txt rhettinger, 2015-07-31 05:13 Some timings review
timings_fasthash_clang.txt rhettinger, 2015-07-31 06:08 Timings using Clang
Messages (3)
msg247735 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2015-07-31 05:13
Speed-up frozenset_hash().  Switching to an entry++ style loop instead of set_next() eliminates much of the loop overhead.  Removing the key=NULL or key==dummy checks eliminates the unpredictable branches and makes the loop vectorizable.  Those benefits outweigh the extra work of doing a multiplication for every row in set table rather than just the non-null, non-dummy entries.

To make sure the overall hash value is unchanged, there are two final clean-up steps to undo the effect of including dummy and null entries.
msg247814 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2015-08-01 15:16
The idea looks interesting and the code looks correct. But the patch decreases readability and I'm not sure, that the benefit is worth it. Timings looks good at first glance, but frozenset hash is cached and is calculated only once per instance. I afraid that the benefit of hash calculation optimization is dwarfed by the time of frozenset creation itself.

If other core developer supports this idea I have no strong objections. See my comments on Rietveld.
msg247815 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-08-01 16:53
New changeset cf707dd190a9 by Raymond Hettinger in branch 'default':
Issue #24762:  Speed-up frozenset_hash() and greatly beef-up the comments.
https://hg.python.org/cpython/rev/cf707dd190a9
History
Date User Action Args
2022-04-11 14:58:19adminsetgithub: 68950
2015-08-01 16:53:52rhettingersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2015-08-01 16:53:10python-devsetnosy: + python-dev
messages: + msg247815
2015-08-01 15:40:05rhettingersetassignee: rhettinger
2015-08-01 15:16:02serhiy.storchakasetassignee: serhiy.storchaka -> (no value)
messages: + msg247814
2015-07-31 06:08:04rhettingersetfiles: + timings_fasthash_clang.txt
2015-07-31 05:13:57rhettingersetfiles: + timings_fasthash.txt
2015-07-31 05:13:36rhettingercreate