GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — bpo-29548: Fix some inefficient call API usage by methane · Pull Request #97 · python/cpython Conversation
|
| PyTuple_SetItem(args, 1, op2); | ||
| if ((result = PyEval_CallObject(func, args)) == NULL) | ||
| PyObject *args[] = {result, op2}; | ||
| if ((result = _PyObject_FastCall(func, args, 2)) == NULL) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Would you mind to move the assignment out of the if() please? "result = ...; if (result == NULL) ...".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| for (;;) { | ||
| PyObject *op2; | ||
|
|
||
| if (args->ob_refcnt > 1) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I expect a ltitle slowdown if the function doesn't support fastcall. For example, a Python object with a call() method.
Can you please try to run a quick benchmark on the following two cases:
In general, I'm in favor of removing such hack, since playing with reference count can lead to complex and annoying bugs. But I would prefer to first see the cost on performances.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
# operator.add is FASTCALL C function
$ ./python -m perf timeit --compare-to $HOME/work/python/cpython/python -s 'L = [0]*10000' -s 'import functools, operator' -- 'functools.reduce(operator.add, L)'
/home/inada-n/work/python/cpython/python: ..................... 498 us +- 3 us
/home/inada-n/work/python/fix-call-usage/python: ..................... 412 us +- 8 us
Median +- std dev: [/home/inada-n/work/python/cpython/python] 498 us +- 3 us -> [/home/inada-n/work/python/fix-call-usage/python] 412 us +- 8 us: 1.21x faster (-17%)
# lambda is Python function (supports FASTCALL)
$ ./python -m perf timeit --compare-to $HOME/work/python/cpython/python -s 'L = [0]*10000' -s 'import functools' -- 'functools.reduce(lambda x,y: x, L)'
/home/inada-n/work/python/cpython/python: ..................... 831 us +- 7 us
/home/inada-n/work/python/fix-call-usage/python: ..................... 788 us +- 11 us
Median +- std dev: [/home/inada-n/work/python/cpython/python] 831 us +- 7 us -> [/home/inada-n/work/python/fix-call-usage/python] 788 us +- 11 us: 1.06x faster (-5%)
# builtin min and max doesn't support FASTCALL
$ ./python -m perf timeit --compare-to $HOME/work/python/cpython/python -s 'L = [0]*10000' -s 'import functools' -- 'functools.reduce(min, L)'
/home/inada-n/work/python/cpython/python: ..................... 1.23 ms +- 0.00 ms
/home/inada-n/work/python/fix-call-usage/python: ..................... 1.42 ms +- 0.04 ms
Median +- std dev: [/home/inada-n/work/python/cpython/python] 1.23 ms +- 0.00 ms -> [/home/inada-n/work/python/fix-call-usage/python] 1.42 ms +- 0.04 ms: 1.16x slower (+16%)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Oh, I missed the "arg" variable.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| func = data->func; | ||
| file = data->file; | ||
|
|
||
| arg = Py_BuildValue("(Oi)", file, (long) mask); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
arg variable is no more used and can be removed, no?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I missed it.
Additionally, argument for "i" format should be int, not (long).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Additionally, argument for "i" format should be int, not (long).
Right, I spotted it as well, but then I forgot to report it, sorry :-) Hopefully you fixed it!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This change removes the "static" declaration from the function slp_switch(). This forces the compiler to adhere to the ABI specification. On i386 and amd64 it is now save to configure stackless with --enable-stacklessfewerregisters, except if you compile for darwin. The flag disables explicit saving of %ebp/%rbp. On Unix-like systems the source file slp_transfer.c now gets compiled with the additional flag -fno-inline-functions instead of -O2. https://bitbucket.org/stackless-dev/stackless/issues/98 (grafted from 4f7698499ad53e5fad61fb415fbfe2c036672a9c)
This replaces the array of qbsr threads with a stack, which allows us to get rid of the stop-the-world call. There was an initialization order bug: registering a new qsbr thread might stop-the-world, but stopping the world requires the thread to already be attached! This will probably make the qsbr scan even slower, but we can improve that in the future. Fixes #97
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.