From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17086 invoked by alias); 20 Nov 2012 13:15:29 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17421 Received: (qmail 8308 invoked from network); 20 Nov 2012 13:15:27 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at linux.vnet.ibm.com does not designate permitted sender hosts) Date: Tue, 20 Nov 2012 21:04:57 +0800 From: Han Pingtian To: zsh-users@zsh.org Cc: schaefer@brasslantern.com Subject: Re: argv subscript range uses too many memory Message-ID: <20121120130457.GD2500@localhost.localdomain> References: <20121108084001.GA7594@localhost.localdomain> <20121108100226.575b0788@pwslap01u.europe.root.pri> <20121110105811.GA7136@localhost.localdomain> <121110065709.ZM4781@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <121110065709.ZM4781@torch.brasslantern.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12112013-1976-0000-0000-000013944D2A On Sat, Nov 10, 2012 at 06:57:09AM -0800, Bart Schaefer wrote: > Further discussion probably should be re-routed to zsh-workers. > > On Nov 10, 6:58pm, Han Pingtian wrote: > } > } Looks like when running with 'print -- "$argv[1,3]", the call trace is > } something like this: > } > } (gdb) bt > } #0 mmap_heap_alloc (n=0x7fff0852e880) at mem.c:449 > } #1 0x000000000045f5f9 in zhalloc (size=1594456) at mem.c:542 > } #2 0x00000000004a4dfa in arrdup (s=0x313b008) at utils.c:3648 > } #3 0x0000000000471fa9 in getarrvalue (v=0x7fff0852ea20) at params.c:2174 > > Ah, yes. Array slices are implemented by copying the entire array and > then extracting the desired subset from the copy. Individual array > elements are string references and therefore copy only the one element. > > Unfortunately this is pretty deeply ingrained in zsh's parameter > expansion implementation and likely requires some serious rewriting to > fix. It might be easier to come up with a way to garbage-collect more > frequently. > > In a loop, the heap allocations are not popped until the loop is done, > IIRC, so you'll end up with a large number of copies of the original > array in the heap with slice results pointing into different parts of > each copy. Maybe there's a narrower scope in which a pushheap/popheap > could be inserted. Looks like I have found the reason of this problem. If I revert this commit: commit 61505654942cb9895a9811fde1dcbb662fd7d66a Author: Bart Schaefer Date: Sat May 7 19:32:57 2011 +0000 29175: optimize freeheap Then the problem will be fixed. Please have a look. Thanks.