Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1370)

Issue 157130: Skip _PyType_Lookup for monomorphic LOAD/STORE_ATTR opcodes (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 6 months ago by Reid Kleckner
Modified:
14 years, 5 months ago
CC:
unladen-swallow_googlegroups.com
Visibility:
Public.

Description

Every generic attribute lookup (ie no overridden __getattribute__) starts by hitting _PyType_Lookup on the type and then maybe hitting the object dict if it exists. If we know the type through feedback, we can 1) cache the result of _PyType_Lookup (the descriptor) and 2) skip the dict lookup if the dict doesn't exist. This is implemented by digging out the code from PyObject_Generic[G|S]etAttr and inlining it with extra constant parameters that are fixed at compilation time. LLVM then propagates those constants through the inlined body and does the Right Thing. 2to3: 22.120000 -> 21.800000: 1.47% faster django: Min: 0.594583 -> 0.582381: 2.10% faster Avg: 0.604536 -> 0.588952: 2.65% faster Significant (t=17.944955, a=0.95) Stddev: 0.00518 -> 0.00330: 57.04% smaller rietveld: Min: 0.392147 -> 0.381066: 2.91% faster Avg: 0.399033 -> 0.389779: 2.37% faster Significant (t=5.930455, a=0.95) Stddev: 0.00808 -> 0.00752: 7.39% smaller slowpickle: Min: 0.389578 -> 0.351653: 10.78% faster Avg: 0.395050 -> 0.352043: 12.22% faster Significant (t=95.702589, a=0.95) Stddev: 0.00317 -> 0.00018: 1631.34% smaller slowspitfire: Min: 0.346205 -> 0.337817: 2.48% faster Avg: 0.347899 -> 0.339405: 2.50% faster Significant (t=8.062652, a=0.95) Stddev: 0.00531 -> 0.00523: 1.61% smaller slowunpickle: Min: 0.193255 -> 0.172468: 12.05% faster Avg: 0.195854 -> 0.172629: 13.45% faster Significant (t=132.029606, a=0.95) Stddev: 0.00124 -> 0.00011: 1057.79% smaller

Patch Set 1 #

Patch Set 2 : Refactor and optimize STORE_ATTR #

Patch Set 3 : Minor cleanups #

Patch Set 4 : Fix a memory leak #

Total comments: 83

Patch Set 5 : Refactored attribute access data and code into a helper class #

Total comments: 45

Patch Set 6 : Round 2, merge with trunk #

Total comments: 8
Unified diffs Side-by-side diffs Delta from patch set Stats (+1313 lines, -116 lines) Patch
M Include/object.h View 1 2 3 4 3 chunks +6 lines, -1 line 0 comments Download
M Lib/test/test_llvm.py View 1 2 3 4 5 3 chunks +461 lines, -0 lines 5 comments Download
M Lib/test/test_sys.py View 1 chunk +1 line, -1 line 0 comments Download
M Objects/object.c View 1 2 3 4 3 chunks +6 lines, -29 lines 0 comments Download
M Objects/typeobject.c View 1 2 3 4 5 10 chunks +73 lines, -23 lines 3 comments Download
M Python/global_llvm_data.h View 2 chunks +2 lines, -2 lines 0 comments Download
M Python/global_llvm_data.cc View 1 chunk +1 line, -0 lines 0 comments Download
M Python/llvm_compile.cc View 1 2 3 4 1 chunk +4 lines, -8 lines 0 comments Download
M Python/llvm_fbuilder.h View 1 2 3 4 5 6 chunks +113 lines, -4 lines 0 comments Download
M Python/llvm_fbuilder.cc View 1 2 3 4 5 9 chunks +375 lines, -17 lines 0 comments Download
M Python/llvm_inline_functions.c View 1 2 3 4 2 chunks +142 lines, -1 line 0 comments Download
M Util/ConstantMirror.h View 5 5 chunks +39 lines, -3 lines 0 comments Download
M Util/ConstantMirror.cc View 5 4 chunks +34 lines, -27 lines 0 comments Download
M Util/PyAliasAnalysis.cc View 1 chunk +1 line, -0 lines 0 comments Download
M Util/PyTypeBuilder.h View 1 3 chunks +55 lines, -0 lines 0 comments Download

Messages

Total messages: 8
Reid Kleckner
PTAL
14 years, 6 months ago (2009-11-23 23:27:33 UTC) #1
Jeffrey Yasskin
http://codereview.appspot.com/157130/diff/1013/37 File Include/object.h (right): http://codereview.appspot.com/157130/diff/1013/37#newcode402 Include/object.h:402: /* Code objects listening for modifications. Added in Unladen. ...
14 years, 6 months ago (2009-11-25 02:32:53 UTC) #2
Reid Kleckner
http://codereview.appspot.com/157130/diff/1013/37 File Include/object.h (right): http://codereview.appspot.com/157130/diff/1013/37#newcode402 Include/object.h:402: /* Code objects listening for modifications. Added in Unladen. ...
14 years, 5 months ago (2009-12-04 20:49:20 UTC) #3
Jeffrey Yasskin
Looks pretty good. Thanks! http://codereview.appspot.com/157130/diff/1013/38 File Lib/test/test_llvm.py (right): http://codereview.appspot.com/157130/diff/1013/38#newcode3063 Lib/test/test_llvm.py:3063: # Check that invalidating the ...
14 years, 5 months ago (2009-12-05 01:38:42 UTC) #4
Reid Kleckner
http://codereview.appspot.com/157130/diff/3001/4002 File Lib/test/test_llvm.py (right): http://codereview.appspot.com/157130/diff/3001/4002#newcode3111 Lib/test/test_llvm.py:3111: sys.setbailerror(False) On 2009/12/05 01:38:42, Jeffrey Yasskin wrote: > Is ...
14 years, 5 months ago (2009-12-05 07:06:29 UTC) #5
Jeffrey Yasskin
LGTM with a few tweaks. Thanks! http://codereview.appspot.com/157130/diff/3001/4002 File Lib/test/test_llvm.py (right): http://codereview.appspot.com/157130/diff/3001/4002#newcode3111 Lib/test/test_llvm.py:3111: sys.setbailerror(False) On 2009/12/05 ...
14 years, 5 months ago (2009-12-07 19:10:34 UTC) #6
Reid Kleckner
Great! I'll commit as soon as I run one more regrtest.py and get some instrumentation ...
14 years, 5 months ago (2009-12-07 20:02:29 UTC) #7
Jeffrey Yasskin
14 years, 5 months ago (2009-12-07 20:36:23 UTC) #8
http://codereview.appspot.com/157130/diff/3008/3013
File Objects/typeobject.c (right):

http://codereview.appspot.com/157130/diff/3008/3013#newcode107
Objects/typeobject.c:107: /* Drop the weakref from the list.  */
On 2009/12/07 20:02:29, Reid Kleckner wrote:
> On 2009/12/07 19:10:34, Jeffrey Yasskin wrote:
> > This automatically happens when you decref and destroy the list, right?
> 
> Yes, but you suggested that I clear out the list before decrefing it in the
last
> round of review.  Is that not quite what you meant?

Oh! Not quite. :) I meant "clear out the field pointing at the list", not clear
out the list itself. So just having "type->tp_code_listeners = NULL;" up above,
like you do, was enough. Sorry for being confusing.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b