Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-44206: Add a version number to dictionary keys #26333

Merged
merged 10 commits into from May 28, 2021

Conversation

@markshannon
Copy link
Contributor

@markshannon markshannon commented May 24, 2021

Apart from adding a version number, this PR also:

  • Reduces the size of dict keys by 8 bytes on 64 bit systems.
  • Reduces the overall code size by ~100 lines

I'll need to run pyperformance before merging, in case this slows things downs.

https://bugs.python.org/issue44206

@markshannon markshannon requested a review from methane as a code owner May 24, 2021
@markshannon markshannon changed the title Add a version number to dictionary keys bpo-44206: Add a version number to dictionary keys May 24, 2021
@markshannon
Copy link
Contributor Author

@markshannon markshannon commented May 24, 2021

Skipping news, as this is strictly internal.

@markshannon markshannon force-pushed the faster-cpython:dict-keys-version branch from 3cfccd7 to 0088371 May 24, 2021

CHECK(0 <= mp->ma_used && mp->ma_used <= usable);
CHECK(IS_POWER_OF_2(keys->dk_size));
CHECK(IS_POWER_OF_2(DK_SIZE(keys)));

This comment has been minimized.

@methane

methane May 25, 2021
Member

This check is now redundant.

@markshannon
Copy link
Contributor Author

@markshannon markshannon commented May 26, 2021

Performance results
Faster on 40, slower on 18. I'm not claiming a speedup, just that it appears to not be slower.

typedef enum {
DICT_KEYS_GENERAL = 0,
DICT_KEYS_UNICODE = 1,
DICT_KEYS_UNICODE_NO_DUMMY = 2,

This comment has been minimized.

@methane

methane May 27, 2021
Member

_Py_dict_lookup() don't have specialized case for DICT_KEYS_UNICODE_NO_DUMMY. Can we delete this kind?

This kind is used only here.

else if (mp->ma_keys->dk_kind == DICT_KEYS_UNICODE) {

But it can be replaced with mp->ma_used > mp->ma_keys->dk_nentries.

@markshannon markshannon merged commit f8a95df into python:main May 28, 2021
11 checks passed
11 checks passed
@github-actions
Check for source changes
Details
@github-actions
Check if generated files are up to date
Details
@github-actions
Windows (x86)
Details
@github-actions
Windows (x64) Windows (x64)
Details
@github-actions
macOS
Details
@github-actions
Ubuntu
Details
@github-actions
Ubuntu SSL tests with OpenSSL
Details
Azure Pipelines PR #20210527.9 succeeded
Details
@travis-ci
Travis CI - Pull Request Build Passed
Details
@bedevere-bot
bedevere/issue-number Issue number 44206 found
Details
@bedevere-bot
bedevere/news "skip news" label found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants