Update declarative function#613
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #613 +/- ##
==========================================
- Coverage 65.99% 65.91% -0.09%
==========================================
Files 270 270
Lines 26590 26623 +33
Branches 3908 3921 +13
==========================================
Hits 17549 17549
- Misses 7992 8025 +33
Partials 1049 1049 🚀 New features to boost your workflow:
|
|
It looks like call_func has to generate a new function with every call. I wonder if the bound dfunc could somehow cache it |
Could you point me to this I do not remember why it is so ? |
| PyObject* pymethod; | ||
| if( numfree > 0 ) | ||
| { | ||
| pymethod = pyobject_cast( freelist[ --numfree ] ); | ||
| _Py_NewReference( pymethod ); | ||
| } | ||
| else | ||
| { | ||
| pymethod = PyType_GenericAlloc( BoundDMethod::TypeObject, 0 ); | ||
| if( !pymethod ) | ||
| return 0; | ||
| } |
There was a problem hiding this comment.
Why did you remove the freelist ?
There was a problem hiding this comment.
Because the first issue said there was issues with GC and suggested doing that and I didn't want to look into it.
But since you asked... I re-added it after digging through methodobject.c and the freelist code that I think simply adding the PyObject_GC_Track fixes the GC issue. The BoundDMethod::TypeObject will still leak references (one per freelist obj) but cant be subclassed so I think that's fine.
Looking at the source of PyEval_EvalCodeEx it creates a new function using _PyFunction_FromConstructor mostly just copying the arguments. I'm not sure if it can avoid this and somehow just use _PyEval_Vector which takes the locals. I'll open a PR if I can get something working. |
Addresses recent issues and updates to use vectorcalls.
A simple timeit calling a dfunc shows about a 30% speedup with this change (but still over order of magnitude slower than a normal py fn call).
I think it is safe to assume the caller "owns" a reference to several of the arguments so this removes a few increfs (pfunc, pself, and argsptr).