Skip to content

Commit bc12f79

Browse files
authored
gh-111786: Optimize for space for _PyEval_EvalFrameDefault on MSVC for PGO (#111794)
In PGO mode, this function caused a compiler error in MSVC. It turns out that optimizing for space only save the day, and is even faster. However, without PGO, this is neither necessary nor slower.
1 parent 6f09f69 commit bc12f79

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

PCbuild/pyproject.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<AdditionalIncludeDirectories>$(PySourcePath)Include;$(PySourcePath)Include\internal;$(PySourcePath)Include\internal\mimalloc;$(PySourcePath)PC;$(IntDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
4242
<PreprocessorDefinitions>WIN32;$(_Py3NamePreprocessorDefinition);$(_PlatformPreprocessorDefinition)$(_DebugPreprocessorDefinition)$(_PydPreprocessorDefinition)%(PreprocessorDefinitions)</PreprocessorDefinitions>
4343
<PreprocessorDefinitions Condition="'$(DisableGil)' == 'true'">Py_NOGIL=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
44+
<PreprocessorDefinitions Condition="'$(SupportPGO)' and ($(Configuration) == 'PGInstrument' or $(Configuration) == 'PGUpdate')">_Py_USING_PGO=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
4445

4546
<Optimization>MaxSpeed</Optimization>
4647
<IntrinsicFunctions>true</IntrinsicFunctions>

Python/ceval.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,15 @@ extern const struct _PyCode_DEF(8) _Py_InitCleanup;
664664
* so consume 3 units of C stack */
665665
#define PY_EVAL_C_STACK_UNITS 2
666666

667+
#if defined(_MSC_VER) && defined(_Py_USING_PGO)
668+
/* gh-111786: _PyEval_EvalFrameDefault is too large to optimize for speed with
669+
PGO on MSVC. Disable that optimization temporarily. If this is fixed
670+
upstream, we should gate this on the version of MSVC.
671+
*/
672+
# pragma optimize("t", off)
673+
/* This setting is reversed below following _PyEval_EvalFrameDefault */
674+
#endif
675+
667676
PyObject* _Py_HOT_FUNCTION
668677
_PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
669678
{
@@ -1080,6 +1089,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
10801089
# pragma GCC diagnostic pop
10811090
#elif defined(_MSC_VER) /* MS_WINDOWS */
10821091
# pragma warning(pop)
1092+
# pragma optimize("", on)
10831093
#endif
10841094

10851095
static void

0 commit comments

Comments
 (0)