Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Is large `if' or `case' statement a potential cause of a slow-down?
- X-seq: zsh-workers 42996
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Is large `if' or `case' statement a potential cause of a slow-down?
- Date: Wed, 13 Jun 2018 16:57:41 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=+CLORvWDINQ06g67Z+5jNBg05RtzFLosuGhKXYU06Is=; b=O4BiAL5waC/rDFlVMlugtKrq49e1v3woe24GI/fzj3zm8l0wuW/wpHfpQorxFjhBXf 8ZZVynZxM1EUgHkWkTnPb6DhQASrPivPeVKP3NDuPfq2j1UIHsDjxeUDGyu/RtJYRnHg YkSHyauaA4O9IpE0ZkseiujnNNVo80YboeN5UFXCpLz137rLmTwpTdh5hBwuGVU4t0V7 TPCQtvqWCv49T6wQWouo6ozeCASVa5RDBk7UReUz8Lo5VLW6a/WsI8t8Aqjb8ETSGaAb yL1dW1EDsyGozthgkWOU4vSf6QNTjgcA+2irIcNTB2xpra83aT7nb0fSz0oJGaPH6JLu 9r4g==
- In-reply-to: <CAKc7PVBLD7M-aFqy_jPHsmscst3n6XP+VnNZi_MBdLaLyUpMFw@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVBLD7M-aFqy_jPHsmscst3n6XP+VnNZi_MBdLaLyUpMFw@mail.gmail.com>
Guys is this silence to not openly state that something is not nice ;)
Or was my post e.g. too long. Because when I replaced significant if
(10 conditions if, elif, ..., fi ) with what I call "hue architecture"
(in FSH everything is about colors), described at the end, I've got
performance gain from 300 ms to 47 ms. This is great, not only fast,
but also implements "modularization" that many people like and that
will help fast-syntax-highlighting.
Hue description: suppose there is:
if [[ b = c ]]; then
...
elif [[ a = "b" ]]; then
...
elif [[ b = c ]]; then
...
elif (( 1 )); then
...
fi
It is then possible to put all conditions into array, just by-hand
copy-paste and wrapping with ', and then run:
local cond;
integer idx=1
for cond in "${HUE_ROUTING__SOME}"; do
cond="$cond && return $idx; "
HUE_ROUTING__SOME[idx]="$cond"
idx+=1
done
To obtain array with:
HUE_ROUTING__SOME=(
'[[ b = c ]] && return 1'
'[[ a = "b" ]] && return 2'
'[[ b = c ]] && return 3'
'(( 1 )) && return 4'
)
And then do:
() { eval "${HUE_ROUTING__SOME[@]}"; }; index=$?
to obtain index into second table that maps 1...N integers on names of
functions to run.
All that may seem long, but almost everything is stored once and
active is only this part (example from upcoming FSH):
() { eval "${FAST_ROUTING__NONE[@]}"; }
${(0)FAST_DISPATCH__NONE[$?]}
So my dispatch table (the second one) holds code to be run like this:
local$'\0'a=b.
So 2 lines instead of big if monolith. So happy :)
On 12 June 2018 at 19:27, Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx> wrote:
> Hello,
> a project (f-sy-h) suffers from what I call a "big-loop". I will
> rewrite it with a trick soon to check, but I though, why guess that a
> big loop, `if' or `case' are not easy for Zsh engine, while I can ask.
> Does someone know a potential marauder script constructs, more
> difficult than less difficult for Zsh execution? Is big-loop/if/case
> among them? I recall Bart mentioned that long assignment statements in
> zcompdump are pretty much slow, IIRC.
>
> On this occasion, I would ask when are functions compiled? Before
> first use, or when defining, or maybe different from these both?
> Functions in .zwc digest are of course compiled and do not need
> compilation at all (?).
>
> To bump up the stake: when sourcing a compiled script that defines
> functions, will there be a wordcode for those function definitions and
> will Zsh use it avoiding compilation?
> --
> Best regards,
> Sebastian Gniazdowski
Messages sorted by:
Reverse Date,
Date,
Thread,
Author