Skip to content

Commit

Permalink
Accessing a single element should optimistically avoid locking for pe…
Browse files Browse the repository at this point in the history
…rformance
  • Loading branch information
DinoV committed Feb 7, 2024
1 parent 11ac6f5 commit 54095de
Show file tree
Hide file tree
Showing 3 changed files with 507 additions and 131 deletions.
4 changes: 3 additions & 1 deletion Include/internal/pycore_dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ static inline PyDictUnicodeEntry* DK_UNICODE_ENTRIES(PyDictKeysObject *dk) {
#define DICT_VERSION_INCREMENT (1 << (DICT_MAX_WATCHERS + DICT_WATCHED_MUTATION_BITS))
#define DICT_WATCHER_MASK ((1 << DICT_MAX_WATCHERS) - 1)

#define DICT_VALUES_SIZE(values) ((uint8_t *)values)[-1]

#ifdef Py_GIL_DISABLED
#define DICT_NEXT_VERSION(INTERP) \
(_Py_atomic_add_uint64(&(INTERP)->dict_state.global_version, DICT_VERSION_INCREMENT) + DICT_VERSION_INCREMENT)
Expand Down Expand Up @@ -255,7 +257,7 @@ _PyDictValues_AddToInsertionOrder(PyDictValues *values, Py_ssize_t ix)
assert(ix < SHARED_KEYS_MAX_SIZE);
uint8_t *size_ptr = ((uint8_t *)values)-2;
int size = *size_ptr;
assert(size+2 < ((uint8_t *)values)[-1]);
assert(size+2 < DICT_VALUES_SIZE(values));
size++;
size_ptr[-size] = (uint8_t)ix;
*size_ptr = size;
Expand Down
17 changes: 1 addition & 16 deletions Objects/clinic/dictobject.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 54095de

Please sign in to comment.