Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure reproducible builds by making JIT stencil header generation deterministic.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve performance of :class:`frozenset` by removing locks in the free-threading build.
35 changes: 25 additions & 10 deletions Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
int probes;
int cmp;

int frozenset = PyFrozenSet_CheckExact(so);

while (1) {
entry = &so->table[i];
probes = (i + LINEAR_PROBES <= mask) ? LINEAR_PROBES: 0;
Expand All @@ -102,13 +104,20 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
&& unicode_eq(startkey, key))
return entry;
table = so->table;
Py_INCREF(startkey);
cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
Py_DECREF(startkey);
if (cmp < 0)
return NULL;
if (table != so->table || entry->key != startkey)
return set_lookkey(so, key, hash);
if (frozenset) {
cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
if (cmp < 0)
return NULL;
} else {
// incref startkey because it can be removed from the set by the compare
Py_INCREF(startkey);
cmp = PyObject_RichCompareBool(startkey, key, Py_EQ);
Py_DECREF(startkey);
if (cmp < 0)
return NULL;
if (table != so->table || entry->key != startkey)
return set_lookkey(so, key, hash);
}
if (cmp > 0)
return entry;
mask = so->mask;
Expand Down Expand Up @@ -2235,10 +2244,16 @@ set_contains_lock_held(PySetObject *so, PyObject *key)
int
_PySet_Contains(PySetObject *so, PyObject *key)
{
assert(so);

int rv;
Py_BEGIN_CRITICAL_SECTION(so);
rv = set_contains_lock_held(so, key);
Py_END_CRITICAL_SECTION();
if (PyFrozenSet_CheckExact(so)) {
rv = set_contains_lock_held(so, key);
} else {
Py_BEGIN_CRITICAL_SECTION(so);
rv = set_contains_lock_held(so, key);
Py_END_CRITICAL_SECTION();
}
return rv;
}

Expand Down
3 changes: 3 additions & 0 deletions Tools/jit/_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def _compute_digest(self) -> str:
hasher.update(PYTHON_EXECUTOR_CASES_C_H.read_bytes())
hasher.update((self.pyconfig_dir / "pyconfig.h").read_bytes())
for dirpath, _, filenames in sorted(os.walk(TOOLS_JIT)):
# Exclude cache files from digest computation to ensure reproducible builds.
if dirpath.endswith("__pycache__"):
continue
for filename in filenames:
hasher.update(pathlib.Path(dirpath, filename).read_bytes())
return hasher.hexdigest()
Expand Down
Loading