zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Caching array parameters' lengths
Date: Sun, 8 May 2016 22:21:30 +0200	[thread overview]
Message-ID: <CAHYJk3RwwU+9bBPuGwxNYLUYy7KvZmkBjVyyjP=kGfMomTCouA@mail.gmail.com> (raw)

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


                 reply	other threads:[~2016-05-08 20:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHYJk3RwwU+9bBPuGwxNYLUYy7KvZmkBjVyyjP=kGfMomTCouA@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).