Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Caching array parameters' lengths
- X-seq: zsh-workers 38431
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: Caching array parameters' lengths
- Date: Sun, 8 May 2016 22:21:30 +0200
- 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==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author