Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:not': 0.03; 'tree': 0.05; 'subject:Python': 0.06; 'memory.': 0.07; 'assuming': 0.09; 'converted': 0.09; 'exception,': 0.09; 'exception.': 0.09; 'overflow': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; "wouldn't": 0.14; 'ast': 0.16; 'entries,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'it".': 0.16; 'exception': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'stack': 0.19; 'fit': 0.20; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'balancing': 0.24; 'module,': 0.24; 'parse': 0.24; 'cc:2**0': 0.24; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'depth': 0.31; 'piece': 0.31; 'maybe': 0.34; 'could': 0.34; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'done': 0.36; 'should': 0.36; 'two': 0.37; 'level': 0.37; 'being': 0.38; 'christian': 0.38; 'that,': 0.38; 'sure': 0.39; 'how': 0.40; 'ian': 0.60; 'hope': 0.61; 'helps': 0.61; 'entire': 0.61; 'matter': 0.61; "you're": 0.61; 'more': 0.64; 'capable': 0.67; 'walk': 0.74; '(ie': 0.84; '2015': 0.84; 'walking': 0.91; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=FAv/xrxPeQiujL0ei9/QYC1w6oeJ4q3Fns7n6C06UGk=; b=r6B9A9rW4XF6+7vLcrg6WRSW+ZcTEb0xld05+ZzbBhAd3F3Ii8EljDUdfdiAmgP5EG uG3G2T9x0huM2v12VdJKUCBeWdNtvPGxkp2nUq46+Kt5Z/gqcD0ZX9nX96VJFUsmkJfq 6mkZXGhrr+sdFRFtXqOnguEvhNOx4fWkO71ng4epzYoVMeKzNFn3i5RS1npHzRqVSakY 0TBn/Nj3DLVS5wiZcwhcw6Jc5UrIjNDW5z2dfKOs9KffxrfsOxjoMSXhPi0SW+D5e1xo 9ne3Xua0LphIjGlzEXg00DalIBvUkif4IoW9nyqOT7WrOO2o3Ede1jN3D3CmkIYCF1pK 0zgQ== MIME-Version: 1.0 X-Received: by 10.50.108.115 with SMTP id hj19mr3927800igb.34.1430582144118; Sat, 02 May 2015 08:55:44 -0700 (PDT) In-Reply-To: References: <87mw1q9jqw.fsf@Equus.decebal.nl> <87383hj4zj.fsf@elektro.pacujo.net> <87d22lx38x.fsf@Equus.decebal.nl> <55432557$0$12994$c3e8da3$5496439d@news.astraweb.com> <87383fo062.fsf@Equus.decebal.nl> <87egmzl4yr.fsf@elektro.pacujo.net> <87a8xnl2r6.fsf@elektro.pacujo.net> <87383fkxy0.fsf@elektro.pacujo.net> Date: Sun, 3 May 2015 01:55:44 +1000 Subject: Re: Python is not bad ;-) From: Chris Angelico Cc: Python Content-Type: text/plain; charset=UTF-8 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430582153 news.xs4all.nl 2831 [2001:888:2000:d::a6]:60726 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89776 On Sun, May 3, 2015 at 1:45 AM, Ian Kelly wrote: > On Sat, May 2, 2015 at 5:42 AM, Marko Rauhamaa wrote: >> Christian Gollwitzer : >> >>> That's why I still think it is a microoptimization, which helps only >>> in some specific cases. >> >> It isn't done for performance. It's done to avoid a stack overflow >> exception. > > If your tree is balanced, then the number of items you would need to > have to get a stack overflow exception would be approximately 2 ** > 1000, which you can't possibly hope to fit into memory. > > If your tree is unbalanced and you're getting a stack overflow > exception, then maybe you should think about balancing it. That's assuming it's a search tree, where you *can* just "think about balancing it". What if it's a parse tree? Let's say you're walking the AST of a Python module, looking for all functions that contain 'yield' or 'yield from' (ie generator functions). To do that, you need to walk the entire depth of the tree, no matter how far that goes. I'm not sure how complex a piece of code would have to be to hit 1000, but it wouldn't be hard to have each level of tree cost you two or three stack entries, so that could come down to just a few hundred. However, while that _is_ more likely to produce an unbalanced tree, it's also that much less capable of being converted into tail recursion. ChrisA