You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it make sense to emit C code instead of calling complex and slow PyArg_ParseXXX() functions? It would emit the most efficient C code to parse arguments.
I don't recall where this idea comes from. Maybe Larry Hastings told me once that he wants to implement this idea :-) I'm sure that Larry has a big plan but lacks time to implement all of his cool ideas.
Using profiled guided optimization (PGO), the compiler should be able to easily detect that error cases are unlikely and mark these code paths as unlikely.
We should probably experiment an implementation to be able to measure the speedup, to be able to say if the idea is worth it or not, in term of performance, since the motivation here is clearly performance.
We can begin with format strings only made of "O" format. Most simple example with divmod(), replace:
The next question is if we should go further with more complex formats. Example with the format() function, replace:
if (!_PyArg_ParseStack(args, nargs, "O|U:format", &value, &format_spec)) { ... }
with:
if (nargs<1||nargs>2) { _PyArg_ErrNumArgs(nargs, 1, 2, "format"); returnNULL; }
value=args[0];
if (nargs==2) {
format_spec=args[1];
if (!PyUnicode_Check(format_spec)) { .. raiseanexception ...; returnNULL; }
/* getargs.c calls PyUnicode_READY(), we should also do it here */if (PyUnicode_READY(format_spec) ==-1) { returnNULL; }
}
else {
format_spec=NULL;
}
See bpo-23867 for the first step (unfinished). After that I planned to inline parsing code for PyArg_ParseTuple() with multiple arguments. Then split PyArg_ParseTupleAndKeywords() on two parts: first unpack keywords to linear sparse array and then handle it as positional arguments.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: