Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit812dd5f

Browse files
committed
Add a bit vector to optimize watcher dispatch
A bit is set in the bit vector iff there is a watcher set at thecorresponding offset in the watcher array. Only notify watchersif at least one bit is set.
1 parentdd41468 commit812dd5f

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

‎Include/internal/pycore_interp.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ struct _is {
174174

175175
PyDict_WatchCallbackdict_watchers[DICT_MAX_WATCHERS];
176176
PyFunction_WatchCallbackfunc_watchers[FUNC_MAX_WATCHERS];
177+
// One bit is set for each non-NULL entry in func_watchers
178+
uint8_tactive_func_watchers;
177179

178180
Py_ssize_tco_extra_user_count;
179181
freefuncco_extra_freefuncs[MAX_CO_EXTRA_USERS];

‎Objects/funcobject.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
#include"structmember.h"// PyMemberDef
1010

1111
staticvoid
12-
handle_func_event(PyFunction_WatchEventevent,PyFunctionObject*func,PyObject*new_value)
12+
notify_func_watchers(PyInterpreterState*interp,PyFunction_WatchEventevent,
13+
PyFunctionObject*func,PyObject*new_value)
1314
{
14-
PyInterpreterState*interp=_PyInterpreterState_GET();
1515
for (inti=0;i<FUNC_MAX_WATCHERS;i++) {
1616
PyFunction_WatchCallbackcb=interp->func_watchers[i];
1717
if ((cb!=NULL)&& (cb(event,func,new_value)<0)) {
@@ -20,6 +20,16 @@ handle_func_event(PyFunction_WatchEvent event, PyFunctionObject *func, PyObject
2020
}
2121
}
2222

23+
staticinlinevoid
24+
handle_func_event(PyFunction_WatchEventevent,PyFunctionObject*func,
25+
PyObject*new_value)
26+
{
27+
PyInterpreterState*interp=_PyInterpreterState_GET();
28+
if (interp->active_func_watchers) {
29+
notify_func_watchers(interp,event,func,new_value);
30+
}
31+
}
32+
2333
int
2434
PyFunction_AddWatcher(PyFunction_WatchCallbackcallback)
2535
{
@@ -28,6 +38,7 @@ PyFunction_AddWatcher(PyFunction_WatchCallback callback)
2838
for (inti=0;i<FUNC_MAX_WATCHERS;i++) {
2939
if (interp->func_watchers[i]==NULL) {
3040
interp->func_watchers[i]=callback;
41+
interp->active_func_watchers |= (1 <<i);
3142
returni;
3243
}
3344
}
@@ -50,6 +61,7 @@ PyFunction_ClearWatcher(int watcher_id)
5061
return-1;
5162
}
5263
interp->func_watchers[watcher_id]=NULL;
64+
interp->active_func_watchers &= ~(1 <<watcher_id);
5365
return0;
5466
}
5567

‎Python/pystate.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
464464
for (inti=0;i<FUNC_MAX_WATCHERS;i++) {
465465
interp->func_watchers[i]=NULL;
466466
}
467+
interp->active_func_watchers=0;
467468

468469
// XXX Once we have one allocator per interpreter (i.e.
469470
// per-interpreter GC) we must ensure that all of the interpreter's

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp