[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-20 Thread STINNER Victor
STINNER Victor added the comment: Serhiy: "I was not sure about documenting this change in Misc/NEWS, but I think that it is not worth to mention it in What's New. This is very minor change. It's effect on any real code is negligible. I have pushed it only because it is trivial, unlikely has

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I was not sure about documenting this change in Misc/NEWS, but I think that it is not worth to mention it in What's New. This is very minor change. It's effect on any real code is negligible. I have pushed it only because it is trivial, unlikely has a

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread STINNER Victor
STINNER Victor added the comment: > New changeset 6535481d610e by Victor Stinner in branch 'default': > Optimize func(*tuple) function call > https://hg.python.org/cpython/rev/6535481d610e Oops. Mercurial is too hard for me /o\ I didn't want to push this change, since Serhiy already pushed the

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread Roundup Robot
Roundup Robot added the comment: New changeset 6535481d610e by Victor Stinner in branch 'default': Optimize func(*tuple) function call https://hg.python.org/cpython/rev/6535481d610e -- ___ Python tracker

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread Joe Jevnik
Joe Jevnik added the comment: CALL_FUNCTION doesn't use extended arg; I don't see what we get by adding some opcode to convert the sequence into a tuple. We also don't want to box up the stack arguments into a tuple because when we do a CALL_FUNCTION to a python function we just copy the

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > Do you have a reference to the more efficient implementation of CALL_FUNCTION? Actually it was about MAKE_FUNCTION. But I think the same is applicable to CALL_FUNCTION. http://comments.gmane.org/gmane.comp.python.devel/157321 --

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread STINNER Victor
STINNER Victor added the comment: > FYI, there is a proposition about constructing arguments tuple and dict in > bytecode instead of ceval.c. This will significantly simplify CALL_FUNCTION > (which will get just one optional tuple and one optional dict). Likely this > idea will be implemented

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread STINNER Victor
STINNER Victor added the comment: > New changeset 15b20201cfa5 by Serhiy Storchaka in branch 'default': Oh. I was cooking a commit, you was faster than me :-) IMHO it's worth to make the optimization in Misc/NEWS, or maybe even in Whats new in Python 3.6. I prepared the text: Issue #26802:

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread STINNER Victor
STINNER Victor added the comment: Good news. On a microbenchmark, the patch makes func(*tuple) between 14% and 18% faster. See attached bench.py. I ran the benchmark on Linux with isolated CPUs to get reliable results. https://haypo-notes.readthedocs.org/microbenchmark.html $ ./python-orig

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: FYI, there is a proposition about constructing arguments tuple and dict in bytecode instead of ceval.c. This will significantly simplify CALL_FUNCTION (which will get just one optional tuple and one optional dict). Likely this idea will be implemented after

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread Roundup Robot
Roundup Robot added the comment: New changeset 15b20201cfa5 by Serhiy Storchaka in branch 'default': Issue #26802: Optimized calling a function with *args only positional arguments. https://hg.python.org/cpython/rev/15b20201cfa5 -- nosy: +python-dev

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: call-function-var-3.patch LGTM. Thank you for your contribution Joe. -- assignee: -> serhiy.storchaka stage: patch review -> commit review ___ Python tracker

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread Josh Rosenberg
Josh Rosenberg added the comment: BTW, for a realistic use case that would be sped up by this patch (possibly a lot), consider a recursive function that is continually doing a "virtual" pop of the first argument, and receiving the rest as varargs, which are then unpacked for the recursive

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread Joe Jevnik
Joe Jevnik added the comment: > It's possible that stararg is already an empty tuple. Is it worth to use it? PyTuple_New(0) should return the unit tuple in most cases: #if PyTuple_MAXSAVESIZE > 0 if (size == 0 && free_list[0]) { op = free_list[0]; Py_INCREF(op); #ifdef

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread STINNER Victor
STINNER Victor added the comment: FYI I ran the full test suite with the second attached patch and all tests pass. By the way, please add a suffix like -2, -3, etc. to your patches next time. It's easier to identify them if they have a different name ;-) --

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread STINNER Victor
STINNER Victor added the comment: call-function-var.patch LGTM. -- ___ Python tracker ___ ___

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread STINNER Victor
STINNER Victor added the comment: +if (!nstar) { +/* There are no positional arguments on the stack or in in a + sequence that was unpacked. */ +return PyTuple_New(0); +} It's possible that stararg is already an empty tuple. Is it worth to

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread Joe Jevnik
Changes by Joe Jevnik : -- type: -> performance ___ Python tracker ___ ___

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread Joe Jevnik
Joe Jevnik added the comment: in _PyEval_EvalCodeWithName we will have already pulled the underlying array out of the tuple subclass and the then we will reconstruct the vararg value in the locals from this array. This means that with this patch we can get: >>> class C(tuple): pass ... >>>

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: stararg can be not exact tuple, but an instance of tuple subclass. Could you provide a microbenchmark that shows the effect of the optimization? -- nosy: +serhiy.storchaka type: behavior -> performance ___ Python

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-19 Thread SilentGhost
Changes by SilentGhost : -- nosy: +haypo, martin.panter, yselivanov stage: -> patch review type: -> behavior ___ Python tracker

[issue26802] Avoid copy in call_function_var when no extra stack args are passed

2016-04-18 Thread Joe Jevnik
New submission from Joe Jevnik: When star unpacking positions into a function we can avoid a copy iff there are no extra arguments coming from the stack. Syntactically this looks like: `f(*args)` This reduces the overhead of the call by about 25% (~30ns on my machine) based on some light