From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12086 invoked by alias); 13 Jun 2018 14:58:06 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 42996 Received: (qmail 13321 invoked by uid 1010); 13 Jun 2018 14:58:06 -0000 X-Qmail-Scanner-Diagnostics: from mail-ot0-f170.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(74.125.82.170):SA:0(-1.9/5.0):. Processed in 1.146274 secs); 13 Jun 2018 14:58:06 -0000 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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: sgniazdowski@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=+CLORvWDINQ06g67Z+5jNBg05RtzFLosuGhKXYU06Is=; b=Bs7MjUGMY5mxGryaokbjnbRsyoEoUCqd2KF1Iah7ZCJMIDcUWRLHuHf0awkwyaVIwz 7IHSzZiFWJhTzHoWC424KjBZxXPdaiLXAm4Norw/Zw6f5j5beNU1xKqlRpPFEgdzkl8N pkwm6i0W1d8/x13uGLhhbcVkYlkDnIBRF9hCdj7ARPLHIVwaHNxDYn3q8YH57ULpgQZ2 6WFbp2xF2XuNAS/oyHLL6BrjL3LO6reXB4NTY0VRVtmHXin4gqxFb2nTmgtqtCXRwcSd DFjqw1Y+z+LlTX8yirp6l3TtK3qGRVVnyFKfyxxt14VWJrHP2burKbDEkVeTY2vhng66 SfNA== X-Gm-Message-State: APt69E3dlYpy3kdkc7uofXOyYVvfzj2ubKCahNoKkqNuzCz586SB1SrX DKe0y1VnUYq273J94n/Wy5ch6OCKOEujnAU0bEf8bQ== X-Google-Smtp-Source: ADUXVKKXafeot/3J9KXG0pEAPrUdmm41zdDJNyKlCWqtOU4ut+6mUF155ZaAZ13MkfQHTxD3i6pgeth6VQkdy2QVh58= X-Received: by 2002:a9d:74d1:: with SMTP id a17-v6mr3541363otl.132.1528901882058; Wed, 13 Jun 2018 07:58:02 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: Sebastian Gniazdowski Date: Wed, 13 Jun 2018 16:57:41 +0200 Message-ID: Subject: Re: Is large `if' or `case' statement a potential cause of a slow-down? To: Zsh hackers list Content-Type: text/plain; charset="UTF-8" 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 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