This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Py_LOCAL_INLINE(type) doesn't actually inline except using MSC
Type: performance Stage: resolved
Components: Versions: Python 3.2
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: stutzbach Nosy List: benjamin.peterson, loewis, ned.deily, pitrou, rpetrov, stutzbach
Priority: low Keywords: patch

Created on 2009-03-24 14:49 by stutzbach, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
inline.patch stutzbach, 2010-04-30 15:00
Messages (9)
msg84089 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2009-03-24 14:49
Below is the relevant snippet from pyport.h.  There are two reasons that
Py_LOCAL_INLINE doesn't actually emit the "inline" keyword (unless
compiling with MSC).  

First, "configure" does not have code to test the compiler and define
USE_INLINE if appropriate.

Second, the code undefines USE_INLINE even if defined! (oops? ;) )

The snippet is replicated with slightly different names near the top of

#undef USE_INLINE /* XXX - set via configure? */

#if defined(_MSC_VER)
/* enable more aggressive optimization for visual studio */
#pragma optimize("agtw", on)
/* ignore warnings if the compiler decides not to inline a function */
#pragma warning(disable: 4710)
/* fastest possible local call under MSVC */
#define Py_LOCAL(type) static type __fastcall
#define Py_LOCAL_INLINE(type) static __inline type __fastcall
#elif defined(USE_INLINE)
#define Py_LOCAL(type) static type
#define Py_LOCAL_INLINE(type) static inline type
#define Py_LOCAL(type) static type
#define Py_LOCAL_INLINE(type) static type
msg104470 - (view) Author: Roumen Petrov (rpetrov) * Date: 2010-04-28 21:57
Configure could call macro to define inline - cf. autoconf manuals.
msg104476 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-04-29 00:01
Py_LOCAL_INLINE is also not used a lot. Usually, the compiler will inline small static functions by itself. Most of the time, we used #defines rather than functions when we want to inline short snippets of code.
msg104641 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-04-30 15:00
Attached is a patch.  

The diff to configure is just what autoconf produces as a result of the diff to

With the patch, pyconfig.h will:
- do nothing if the compiler supports the "inline" keyword
- #define inline to __inline or __inline__ if that's the compiler supports
- #define inline to nothing if the compiler doesn't support inlining

The patch also updates pyport.h and _sre.c appropriately.
msg104644 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-04-30 15:06
I should add that the patch is against the py3k branch, since it's too late for performance improvements to land in trunk.
msg105940 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-05-17 21:38
The patch looks ok to me.
msg115275 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-08-31 19:52
Committed in r84379
msg115621 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2010-09-05 00:34
Note: autoreconf failure caused by r84379 was fixed by r84512.
msg115625 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-09-05 04:43
Ned, thanks for bringing that to my attention.  I might have missed it otherwise.

I had run "autoconf" but had not known to run "autoreconf", so I had missed the failure there.  *embarrassed*

Benjamin, thanks for fixing my error!
Date User Action Args
2022-04-11 14:56:46adminsetgithub: 49803
2010-09-05 04:43:23stutzbachsetnosy: + benjamin.peterson
messages: + msg115625
2010-09-05 00:34:40ned.deilysetnosy: + ned.deily
messages: + msg115621
2010-08-31 19:52:02stutzbachsetstatus: open -> closed
messages: + msg115275

keywords: - needs review
resolution: accepted
stage: patch review -> resolved
2010-05-17 21:38:31pitrousetnosy: + loewis
messages: + msg105940
2010-04-30 15:06:35stutzbachsetmessages: + msg104644
2010-04-30 15:00:07stutzbachsetkeywords: + patch, needs review
files: + inline.patch
messages: + msg104641

stage: needs patch -> patch review
2010-04-29 00:01:44pitrousetnosy: + pitrou
messages: + msg104476
2010-04-28 21:57:32rpetrovsetnosy: + rpetrov
messages: + msg104470
2010-04-27 15:28:13stutzbachsetpriority: low
assignee: stutzbach
stage: needs patch
type: performance
versions: + Python 3.2, - Python 3.0, Python 3.1, Python 2.7
2009-03-24 14:49:18stutzbachcreate