8000 Accessing a single element should optimistically avoid locking for pe… · python/cpython@39c1a11 · GitHub
[go: up one dir, main page]

Skip to content

Commit 39c1a11

Browse files
committed
Accessing a single element should optimistically avoid locking for performance
1 parent 58cb634 commit 39c1a11

File tree

3 files changed

+507
-131
lines changed

3 files changed

+507
-131
lines changed

Include/internal/pycore_dict.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ static inline PyDictUnicodeEntry* DK_UNICODE_ENTRIES(PyDictKeysObject *dk) {
205205
#define DICT_WATCHER_MASK ((1 << DICT_MAX_WATCHERS) - 1)
206206
#define DICT_WATCHER_AND_MODIFICATION_MASK ((1 << (DICT_MAX_WATCHERS + DICT_WATCHED_MUTATION_BITS)) - 1)
207207

208+
#define DICT_VALUES_SIZE(values) ((uint8_t *)values)[-1]
209+
208210
#ifdef Py_GIL_DISABLED
209211
#define DICT_NEXT_VERSION(INTERP) \
210212
(_Py_atomic_add_uint64(&(INTERP)->dict_state.global_version, DICT_VERSION_INCREMENT) + DICT_VERSION_INCREMENT)
@@ -250,7 +252,7 @@ _PyDictValues_AddToInsertionOrder(PyDictValues *values, Py_ssize_t ix)
250252
assert(ix < SHARED_KEYS_MAX_SIZE);
251253
uint8_t *size_ptr = ((uint8_t *)values)-2;
252254
int size = *size_ptr;
253-
assert(size+2 < ((uint8_t *)values)[-1]);
255+
assert(size+2 < DICT_VALUES_SIZE(values));
254256
size++;
255257
size_ptr[-size] = (uint8_t)ix;
256258
*size_ptr = size;

Objects/clinic/dictobject.c.h

Lines changed: 1 addition & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0