Skip to content

Commit 59d6fca

Browse files
authored
Merge branch 'main' into gh-145866-call_intrinsic_2
2 parents d1503e2 + 7dc2f52 commit 59d6fca

File tree

6 files changed

+45
-8
lines changed

6 files changed

+45
-8
lines changed

Doc/whatsnew/3.15.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ mimetypes
842842
* Add ``application/sql`` and ``application/vnd.sqlite3``.
843843
(Contributed by Charlie Lin in :gh:`145698`.)
844844
* Add ``image/jxl``. (Contributed by Foolbar in :gh:`144213`.)
845+
* Add ``application/efi``. (Contributed by Charlie Lin in :gh:`145720`.)
845846
* Add the following MIME types:
846847

847848
- ``application/vnd.ms-cab-compressed`` for ``.cab`` extension

Lib/mimetypes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ def _default_mime_types():
478478
'.js' : 'text/javascript',
479479
'.mjs' : 'text/javascript',
480480
'.dcm' : 'application/dicom',
481+
'.efi' : 'application/efi',
481482
'.epub' : 'application/epub+zip',
482483
'.gz' : 'application/gzip',
483484
'.json' : 'application/json',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve multithreaded scaling of PyMutex in low-contention scenarios by reloading the lock's internal state, without slowing down high-contention scenarios.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``application/efi`` MIME type to :mod:`mimetypes`.

Python/lock.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ static const PyTime_t TIME_TO_BE_FAIR_NS = 1000*1000;
2727
// enabled.
2828
#if Py_GIL_DISABLED
2929
static const int MAX_SPIN_COUNT = 40;
30+
static const int RELOAD_SPIN_MASK = 3;
3031
#else
3132
static const int MAX_SPIN_COUNT = 0;
33+
static const int RELOAD_SPIN_MASK = 1;
3234
#endif
3335

3436
struct mutex_entry {
@@ -79,6 +81,16 @@ _PyMutex_LockTimed(PyMutex *m, PyTime_t timeout, _PyLockFlags flags)
7981
};
8082

8183
Py_ssize_t spin_count = 0;
84+
#ifdef Py_GIL_DISABLED
85+
// Using thread-id as a way of reducing contention further in the reload below.
86+
// It adds a pseudo-random starting offset to the recurrence, so that threads
87+
// are less likely to try and run compare-exchange at the same time.
88+
// The lower bits of platform thread ids are likely to not be random,
89+
// hence the right shift.
90+
const Py_ssize_t tid = (Py_ssize_t)(_Py_ThreadId() >> 12);
91+
#else
92+
const Py_ssize_t tid = 0;
93+
#endif
8294
for (;;) {
8395
if ((v & _Py_LOCKED) == 0) {
8496
// The lock is unlocked. Try to grab it.
@@ -92,6 +104,9 @@ _PyMutex_LockTimed(PyMutex *m, PyTime_t timeout, _PyLockFlags flags)
92104
// Spin for a bit.
93105
_Py_yield();
94106
spin_count++;
107+
if (((spin_count + tid) & RELOAD_SPIN_MASK) == 0) {
108+
v = _Py_atomic_load_uint8_relaxed(&m->_bits);
109+
}
95110
continue;
96111
}
97112

Python/sysmodule.c

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3878,20 +3878,38 @@ static PyStructSequence_Desc emscripten_info_desc = {
38783878

38793879
EM_JS(char *, _Py_emscripten_runtime, (void), {
38803880
var info;
3881-
if (typeof navigator == 'object') {
3881+
if (typeof process === "object") {
3882+
if (process.versions?.bun) {
3883+
info = `bun v${process.versions.bun}`;
3884+
} else if (process.versions?.deno) {
3885+
info = `deno v${process.versions.deno}`;
3886+
} else {
3887+
// As far as I can tell, every JavaScript runtime puts "node" in
3888+
// process.release.name. Pyodide once checked for
3889+
//
3890+
// process.release.name === "node"
3891+
//
3892+
// and this is apparently part of the reason other runtimes started
3893+
// lying about it. Similar to the situation with userAgent.
3894+
//
3895+
// But just in case some other JS runtime decides to tell us what it
3896+
// is, we'll pick it up.
3897+
const name = process.release?.name ?? "node";
3898+
info = `${name} ${process.version}`;
3899+
}
3900+
// Include v8 version if we know it
3901+
if (process.versions?.v8) {
3902+
info += ` (v8 ${process.versions.v8})`;
3903+
}
3904+
} else if (typeof navigator === "object") {
38823905
info = navigator.userAgent;
3883-
} else if (typeof process == 'object') {
3884-
info = "Node.js ".concat(process.version);
38853906
} else {
38863907
info = "UNKNOWN";
38873908
}
3888-
var len = lengthBytesUTF8(info) + 1;
3889-
var res = _malloc(len);
3890-
if (res) stringToUTF8(info, res, len);
38913909
#if __wasm64__
3892-
return BigInt(res);
3910+
return BigInt(stringToNewUTF8(info));
38933911
#else
3894-
return res;
3912+
return stringToNewUTF8(info);
38953913
#endif
38963914
});
38973915

0 commit comments

Comments
 (0)