Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Caching array parameters' lengths



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