Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,
	T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=mime-version:date:message-id:subject:from:to;
        bh=6+k3HtL0/uf0dxXHoN0LEW72bpdvQXQziNnsKnhfZZg=;
        b=FfvTva0m79lzMldv+9lYdiChqQdV3bzWxLlFuy/FHuvk4wOvTtjD4h8DOsBYpwmQTh
         XeANHad+r8QM/5XrTxGKWLNZHyhFMcgZ0ff5R7zVnde7jxZimdc1knZnee7GYn4kUAtd
         FiWahLE+RJ7mY0zQyyUzWGB/2XtehfOaa1ueMOhA8NS1O8izshab98ZnU4FBDRYlXir2
         ICrz01cOyxPE2H2PaDke0At3ehIyQW6pzUVBSW+whMfeqYpZgkbibDbmLtUxbwDoCQb+
         9nUdxpspkSyy6bLrmFWPiKv0Rg1SQbpHRzfbH6nYFjY3r6E7VmGfT5VI9vvCuLyZh4ED
         kvwg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:date:message-id:subject:from:to;
        bh=6+k3HtL0/uf0dxXHoN0LEW72bpdvQXQziNnsKnhfZZg=;
        b=GMyur6BLYRX8K4SNC/T/3gnIMJtPwlvPEETBpDca3PSkLXCrHGdKGUhVIBaoaquWdA
         v1LBOr293ysP2D1SsmV8LEOHXmeDHKvMPIDfNDWQpalzfDjsUnKRMrxieakSF8LnFx60
         CktKIX14CiN5809IBrwFlrv01Rsn/0DV+BLMuovQGQzt04j8MSkzJofJP0PskQqDl+0O
         P83m9wB4/Oyn40M5GOyWGFHF+lue8MRUC6OrLhUDWcIYFni2AQW5uyRpYT0qyNSusfzA
         4fVj5thmGTIqGbxdLwggpcm6V4gBZh2vVVZZbNcbb1HFTYR7tv+tRr9TDt78PG5f0c5j
         cEtA==
X-Gm-Message-State: AOPr4FVHIOqefxKVyeqPHLMWejSRwzZXlpGeOrXve6LntrXPBE3cXcJca1ukq4+MpVlyQRYGwBSRUl8dLG8MAw==
MIME-Version: 1.0
X-Received: by 10.55.99.214 with SMTP id x205mr32738796qkb.3.1462738890441;
 Sun, 08 May 2016 13:21:30 -0700 (PDT)
Date: Sun, 8 May 2016 22:21:30 +0200
Message-ID: <CAHYJk3RwwU+9bBPuGwxNYLUYy7KvZmkBjVyyjP=kGfMomTCouA@mail.gmail.com>
Subject: Caching array parameters' lengths
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh workers <zsh-workers@zsh.org>
Content-Type: text/plain; charset=UTF-8
X-Seq: zsh-workers 38431

I've pushed a branch (mikachu/badarrays) that tries to do this. There
are some things that don't work, all tests fail if you enable it
globally with asserts, and most parameter/array tests fail with the
results just being wrong regardless of asserts. The top two commits
add -c and -C to typeset to control if a parameter uses the cached
length, and whether the cached length is checked via assert,
respectively. In the cases where it does work, there is noticable
improvement:

% typeset -a a
% a=(i{1..1000000})
% time (repeat 5000; do : $a[-1]; done)
( repeat 5000; do; : $a[-1]; done; )  15.24s user 0.01s system 98% cpu
15.515 total

% typeset -ca a
% time (repeat 5000; do : $a[-1]; done)
( repeat 5000; do; : $a[-1]; done; )  0.03s user 0.00s system 89% cpu
0.040 total

And it does grab the correct element:
% time (repeat 5000; do echo $a[-1]; done)
...
i1000000
i1000000
i1000000
...
( repeat 5000; do; echo $a[-1]; done; )  0.04s user 0.01s system 91%
cpu 0.064 total

So if anyone feels like this is a worthwhile cause, and is less lost
than I am in the intricacies of parameter substitution code, feel free
to take a look.

Also, don't blame Daniel for any of this, he just split up my original
branch into separate commits when I looked into this last time, I'm
responsible for all the brokenness.

-- 
Mikael Magnusson

