Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeder1.xsusenet.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'languages.': 0.04; 'cpython': 0.05; 'interpreter': 0.05; 'layers': 0.07; 'method.': 0.07; 'suppose': 0.07; '(ie.': 0.09; 'attributes': 0.09; 'exist,': 0.09; 'high-level': 0.09; 'oop,': 0.09; 'python': 0.11; 'anyway': 0.14; 'language.': 0.14; "'b'": 0.16; '(it': 0.16; 'bytecode': 0.16; 'conditional': 0.16; 'consulted': 0.16; 'dict': 0.16; 'distinct': 0.16; 'enough.': 0.16; 'for,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'instantiated': 0.16; 'itself,': 0.16; 'lookups': 0.16; 'macros': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; "object's": 0.16; 'ought': 0.16; 'received:192.168.1.4': 0.16; 'type)': 0.16; 'language': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'trying': 0.19; "python's": 0.19; '>>>': 0.22; 'programming': 0.22; 'header:User-Agent:1': 0.23; 'rapidly': 0.24; '(or': 0.24; 'question': 0.24; 'equivalent': 0.26; 'this:': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'appear': 0.29; 'feature': 0.29; "i'm": 0.30; 'code': 0.31; 'usually': 0.31; 'minor': 0.31; 'own,': 0.31; 'class': 0.32; 'call.': 0.33; 'cases': 0.33; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'really': 0.36; 'belong': 0.36; 'crazy': 0.36; 'done': 0.36; "didn't": 0.36; 'method': 0.36; 'possible': 0.36; 'searching': 0.37; 'so,': 0.37; 'two': 0.37; 'represent': 0.38; 'to:addr:python-list': 0.38; 'little': 0.38; 'does': 0.39; 'use.': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'even': 0.60; 'expression': 0.60; 'first': 0.61; 'name': 0.63; 'such': 0.63; 'more': 0.64; 'sound': 0.68; 'construction': 0.72; 'delegates': 0.74; 'increase': 0.74; 'special': 0.74; 'gain': 0.79; '(increase': 0.84; "class's": 0.84; 'details...': 0.84; 'do:': 0.91; 'urge': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=DZWZq5dW c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=SY9aFQKHIdAA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=5ANokUeuAAAA:8 a=B5DUjjRS0Nhm-CzFEEYA:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett@:2500 Date: Sat, 16 May 2015 02:16:52 +0100 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Building CPython References: <7JN4x.37133$Q41.15375@fx25.am4> <6w35x.645690$I97.19867@fx31.am4> <874mnfunpn.fsf@elektro.pacujo.net> <87bnhmgqrx.fsf@elektro.pacujo.net> <87twvdsbom.fsf@elektro.pacujo.net> In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1431739023 news.xs4all.nl 2924 [2001:888:2000:d::a6]:56362 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90704 On 2015-05-16 01:43, BartC wrote: > On 15/05/2015 23:44, Marko Rauhamaa wrote: >> BartC : >> >>> What /is/ a method lookup? Is it when you have this: >>> >>> A.B() >>> >>> and need to find whether the expression A (or its class or type) has a >>> name B associated with it? (And it then needs to check whether B is >>> something that can be called.) >>> >>> If so, does that have to be done using Python's Dict mechanism? (Ie. >>> searching for a key 'B' by name and seeing if the object associated >>> with it is a method. That does not sound efficient.) >> >> That is a general feature among high-level programming languages. In >> Python, it is even more complicated: >> >> * first the object's dict is looked up for the method name >> >> * if the method is not found (it usually isn't), the dict of the >> object's class is consulted >> >> * if the method is found (it usually is), a function object is >> instantiated that delegates to the class's method and embeds a "self" >> reference to the object to the call >> >> IOW, two dict lookups plus an object construction for each method call. > > OK, I didn't know that objects have their own set of attributes that are > distinct from the class they belong to. I really ought to learn more > Python!. > > (Yet, I have this crazy urge now to create my own bytecode interpreter > for, if not exactly Python itself, then an equivalent language. Just to > see if I can do any better than CPython, given the same language > restraints. > > Although I'm hampered a little by not knowing Python well enough. Nor > OOP, but those are minor details... Anyway it sounds more fun than > trying to decipher the layers of macros and conditional code that appear > to be the CPython sources.) > > > IOW, two dict lookups plus an object construction for each method call. > > I suppose in many cases an object will have no attributes of its own, > and so it can rapidly bypass the first lookup. I don't understand the > need for an object creation (to represent A.B so that it can call it?) > but perhaps such an object can already exist, prepared ready for use. > It's possible to do: f = A.B ... f() so it's necessary to have an object for A.B. The question is how much you would gain from optimising A.B() as a special case (increase in speed vs increase in complexity).