classification
Title: Drop CALL_PROFILE special build?
Type: Stage:
Components: Versions: Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Jeremy.Hylton, haypo, python-dev
Priority: normal Keywords: patch

Created on 2016-11-25 09:02 by haypo, last changed 2017-03-31 16:36 by dstufft. This issue is now closed.

Files
File name Uploaded Description Edit
remove_call_profile.patch haypo, 2016-11-25 09:03 review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (4)
msg281687 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2016-11-25 09:02
Python/ceval.c contains conditional code to compute statistics on function calls when CALL_PROFILE is defined.

Extract of Misc/SpecialBuilds.txt:

    CALL_PROFILE
    ------------

    Count the number of function calls executed.

    When this symbol is defined, the ceval mainloop and
    helper functions count the number of function calls
    made.  It keeps detailed statistics about what kind of
    object was called and whether the call hit any of the
    special fast paths in the code.

Statistics can later be collected by sys.callstats().

I'm unable to find any unit test on this feature. The feature was added in Python 2.3.1 by the changeset 16856c9514e0 in 2003:
---
changeset:   27712:16856c9514e0
branch:      legacy-trunk
user:        Jeremy Hylton <jeremy@alum.mit.edu>
date:        Wed Feb 05 23:13:00 2003 +0000
files:       Include/ceval.h Include/compile.h Misc/SpecialBuilds.txt Python/ceval.c Python/compile.c Python/sysmodule.c
description:
Small function call optimization and special build option for call stats.

-DCALL_PROFILE: Count the number of function calls executed.

When this symbol is defined, the ceval mainloop and helper functions
count the number of function calls made.  It keeps detailed statistics
about what kind of object was called and whether the call hit any of
the special fast paths in the code.

Optimization:

When we take the fast_function() path, which seems to be taken for
most function calls, and there is minimal frame setup to do, avoid
call PyEval_EvalCodeEx().  The eval code ex function does a lot of
work to handle keywords args and star args, free variables,
generators, etc.  The inlined version simply allocates the frame and
copies the arguments values into the frame.

The optimization gets a little help from compile.c which adds a
CO_NOFREE flag to code objects that don't have free variables or cell
variables.  This change allows fast_function() to get into the fast
path with fewer tests.

I measure a couple of percent speedup in pystone with this change, but
there's surely more that can be done.
---

The changeset adds an optimization using CO_NOFREE and the CALL_PROFILE feature.

My problem is that with my work on FASTCALL, it became harder to track where the functions are called in practice. It maybe out of the Python/ceval.c file. I'm not sure that statistics are still computed correctly after my FASTCALL changes, and I don't know how to check it.

Python has already sys.setprofile(), cProfile and profile modules. There is also sys.settrace(). Do we still need CALL_PROFILE?

Attached patch removes the feature:

* Calling the the untested and undocumented sys.callstats() function now emits a DeprecationWarning warning
* Remove the PyEval_GetCallStats() function and its documentation

PyEval_GetCallStats() seems to be part of the stable API, but I don't expect that anyone uses it outside the CPython source code since it requires to rebuild CPython with a special build flag (-D CALL_PROFILE).
msg281860 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2016-11-28 10:56
Jeremy Hylton, the author of the feature, approved the removal of CALL_PROFILE:
https://mail.python.org/pipermail/python-dev/2016-November/146866.html

Raymond Hettinger is also ok to remove it:
"This seems reasonable to me.  I've never used or needed this special build; StackOverflow has no mention of it; and a Google search comes up nearly empty.   That said, it might be worthwhile to check with Jeremy to get his thoughts before removing his code."
https://mail.python.org/pipermail/python-dev/2016-November/146864.html
msg281862 - (view) Author: Roundup Robot (python-dev) Date: 2016-11-28 11:05
New changeset 5aa2171ee43f by Victor Stinner in branch 'default':
Remove CALL_PROFILE special build
https://hg.python.org/cpython/rev/5aa2171ee43f
msg281863 - (view) Author: Roundup Robot (python-dev) Date: 2016-11-28 11:06
New changeset 07d8272d61e7 by Victor Stinner in branch 'default':
Issue #28799: Update Misc/SpecialBuilds.txt
https://hg.python.org/cpython/rev/07d8272d61e7
History
Date User Action Args
2017-03-31 16:36:20dstufftsetpull_requests: + pull_request939
2016-11-28 17:23:31hayposetstatus: open -> closed
resolution: fixed
2016-11-28 11:06:20python-devsetmessages: + msg281863
2016-11-28 11:05:17python-devsetnosy: + python-dev
messages: + msg281862
2016-11-28 10:56:04hayposetmessages: + msg281860
2016-11-26 08:27:34rhettingersetnosy: + Jeremy.Hylton
2016-11-25 09:03:23hayposetfiles: + remove_call_profile.patch
keywords: + patch
2016-11-25 09:02:53haypocreate