mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
gh-109587: Allow "precompiled" perf-trampolines to largely mitigate the cost of enabling perf-trampolines (#109666)
This commit is contained in:
parent
3d2f1f0b83
commit
21f068d80c
8 changed files with 199 additions and 10 deletions
|
|
@ -1556,6 +1556,36 @@ _testinternalcapi_test_long_numbits_impl(PyObject *module)
|
|||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
compile_perf_trampoline_entry(PyObject *self, PyObject *args)
|
||||
{
|
||||
PyObject *co;
|
||||
if (!PyArg_ParseTuple(args, "O!", &PyCode_Type, &co)) {
|
||||
return NULL;
|
||||
}
|
||||
int ret = PyUnstable_PerfTrampoline_CompileCode((PyCodeObject *)co);
|
||||
if (ret != 0) {
|
||||
PyErr_SetString(PyExc_AssertionError, "Failed to compile trampoline");
|
||||
return NULL;
|
||||
}
|
||||
return PyLong_FromLong(ret);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
perf_trampoline_set_persist_after_fork(PyObject *self, PyObject *args)
|
||||
{
|
||||
int enable;
|
||||
if (!PyArg_ParseTuple(args, "i", &enable)) {
|
||||
return NULL;
|
||||
}
|
||||
int ret = PyUnstable_PerfTrampoline_SetPersistAfterFork(enable);
|
||||
if (ret == 0) {
|
||||
PyErr_SetString(PyExc_AssertionError, "Failed to set persist_after_fork");
|
||||
return NULL;
|
||||
}
|
||||
return PyLong_FromLong(ret);
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef module_functions[] = {
|
||||
{"get_configs", get_configs, METH_NOARGS},
|
||||
|
|
@ -1613,6 +1643,8 @@ static PyMethodDef module_functions[] = {
|
|||
{"run_in_subinterp_with_config",
|
||||
_PyCFunction_CAST(run_in_subinterp_with_config),
|
||||
METH_VARARGS | METH_KEYWORDS},
|
||||
{"compile_perf_trampoline_entry", compile_perf_trampoline_entry, METH_VARARGS},
|
||||
{"perf_trampoline_set_persist_after_fork", perf_trampoline_set_persist_after_fork, METH_VARARGS},
|
||||
_TESTINTERNALCAPI_WRITE_UNRAISABLE_EXC_METHODDEF
|
||||
_TESTINTERNALCAPI_TEST_LONG_NUMBITS_METHODDEF
|
||||
{NULL, NULL} /* sentinel */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue