From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2825 invoked by alias); 7 May 2011 17:07:01 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29172 Received: (qmail 14608 invoked from network); 7 May 2011 17:06:47 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.220.171 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=gJUZStPKIrh93QyiA/IR2e8GJ7Kc5wcWKYFMbGq1sdY=; b=OYSUBV7SfwVdVoW1k1ofQD1gWtFoZ2zvY4cf14eyli/hA2yAPb9m8o6RQ21gnZAKDj ssldMo+c1VkNip5APtE9m0BvCV2EndIEv2GfMAS9lGL8C71S+okshnvelRxqks9Wrgll /VIuMxazEK1kvoVALuPCWj4vARWAb11x856Ng= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=UfoTFfiqpV7OhYBly8fbApqIwK1fYOJg7brW7uoU6mIOXC45qdWOYMAEjV8hLSSb4q j49M05XYu4sbqzoGCkgTLNvs/37OAouCQInF0li4VS9zcDnDMOl4FlXtSAMtLIIRTuSU N0wE+ljX2/d+rre9VbFB3Tq9BD62cWFJfLh3I= MIME-Version: 1.0 Date: Sat, 7 May 2011 19:00:17 +0200 Message-ID: Subject: the source of slow large for loops From: Mikael Magnusson To: zsh workers Content-Type: text/plain; charset=UTF-8 I don't know if anyone looked into why things like for i in {1..700000}; do true; done is extremely slow in zsh, so I did now. Turns out zhalloc is extremely slow, and for the above loop, one particular line runs 12049901132 times according to gcov. (It takes around 10 minutes). If I add early returns of malloc() and realloc() to zhalloc and hrealloc, the loop runs in 3 seconds (but leaks a couple of hundred megabytes memory). This is mostly a FYI thing, not really intending to do anything about it or expecting anything, but I've always wondered where the slowness was and now I know. :) -- Mikael Magnusson