From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10222 invoked by alias); 3 Jun 2018 00:22:36 -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: 42921 Received: (qmail 28026 invoked by uid 1010); 3 Jun 2018 00:22:36 -0000 X-Qmail-Scanner-Diagnostics: from park01.gkg.net 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(205.235.26.22):SA:0(-1.4/5.0):. Processed in 0.419578 secs); 03 Jun 2018 00:22:36 -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.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_PASS,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.1 X-Envelope-From: SRS0=U+2j=IT=yahoo.co.uk=okiddle@bounces.park01.gkg.net X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Virus-Scanned: by amavisd-new at gkg.net Authentication-Results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1527893724; bh=bRqlXbUFaAw3Rho+XdN3DskqecQbV7ZttoKemWqT4Eg=; h=From:References:To:Subject:Date:From:Subject; b=i60HXazNsmbYbGiGOVgTZE41u1wNPDA09AQVk8nKufyTkHow/LhOq09i+8PJco18diJI9QKrxQ3gs1oScSxmPYZZKg+wkWvKaO7iN53s8kYj9U3/oP4NPEiOqRKyx0M2d1SYXmO8k3Fh2S/puY9sNtPk49eAcnAWBARVIIXZrGRuCe+Yzq/mtzMnkMj+eRP1fLXcW2BJkvG48PDRpiqgkuU+u6zKBB3lLu6p5dfxF12WRAtrZfGP7m09PeBIX8GKNpTckDSdl1Ap/SeQCohs02gfUKIl664qt4dPjl5/RrsVop0gYSnHh8j/kFGFhKinSlbE2cgQk8ha5JxwkKxuNg== X-YMail-OSG: C4rMi9wVM1kG7KVHRLQXFtzgk5bz.XIiGGqbPjT1Ly.INGDZu4jyLJ1VPm.nzJy fT5u1PWclRHWOOw5QMeFGOqyXku4I4LqxRRDlpRJQ3_pYt9wKZSyJ5VpKEzYQhf.2yqRsX24vUYo 0VRC1BOueg5O6vJA.yYzAvKssgjDuNVnwIR6trhjmB_VZ1Ovk.xaHRNP_Y_BHTRSdrzGFIoatsUP DKBa6Dk6VSbHL_axoBvgH82xoidJIIQCRH9yfjbMype.xCXpMoWzBd9tBUt6AsJy_GxGJhuaJG7C ruHfH6fxvvwc2QvaFYS4uFr7VW2GslNoJFAD4JXchEatIry1pfsm.t05AIcTwgmu6aQad10TbLx2 zaBIm_yW1ajO33UqZv7ecL841xqSJD_f6OCVdqKJEOwsnsj7UXpOldlPYHmWwDj.aWZ8pbl7ry1l uUebB1fGMx9NV6MO1An8GauPbfr2dmhBt8upgp9QaQW_pKOE0LAv3LKH5l2U3SbbNU9RY4xe26Vt SMny8i__9tNy1wZKPdDeZppj8DlccnNMaCWFWJfjc45lw8xdPy2ZwbYnChZOP5v_Kz0xixbuDmUB 1HnhSdcsXlhwqqdUIABvS5hJ.DiIw6sfSLIurKV6_mA4DrI8_9rn33o5ubN50CFr7nFgLEOLeyGD BJiEHn.4oFIfgSvmw In-reply-to: <20180601133048.m7crvdzodzntxcsq@NUC.doronbehar.com> From: Oliver Kiddle References: <20180526161403.4860-1-doron.behar@gmail.com> <20180526161403.4860-2-doron.behar@gmail.com> <5942.1527504539@thecus> <20180529153821.nmwa5yojlusioxti@NUC.doronbehar.com> <13666.1527631249@thecus> <20180530124707.xp6loetwnplkypk2@NUC.doronbehar.com> <16604.1527694987@thecus> <20180601071850.4z3h6cvkuvva3nby@NUC.doronbehar.com> <20180601133048.m7crvdzodzntxcsq@NUC.doronbehar.com> To: zsh-workers@zsh.org Subject: Re: [PATCH 1/1] Squashed commit of the following: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <31971.1527893117.1@thecus> Content-Transfer-Encoding: 8bit Date: Sat, 02 Jun 2018 00:45:17 +0200 Message-ID: <31972.1527893117@thecus> Doron Behar wrote: > However, the bad news is that I'm afraid that calling `luarocks config` > twice like that whenever I query the cache validity, is a huge > performance hit. > The solution which will most likely best solve this issue is to use a > similar cache mechanism for these values as well. This *inner* cache's Sounds rather complicated but perhaps necessary depending on just how slow it is. A global variable – typically named _cache_… – is one option for caching that avoids much of the complexity of the disk cache mechanism if the lifetime of the session is an appropriate policy for how long to retain the cached information. > I'd be glad to get some feedback, thanks! > (( $+functions[___luarocks_manually_store_cache_configs_paths] )) || > ___luarocks_manually_store_cache_configs_paths(){ > user_config_path="$(_call_program user_config_path luarocks config --user-config)" > system_config_path="$(_call_program system_config_path luarocks config --system-config)" These variables should be declared local. If the intention is for them to be global, use typeset -g and prefix the names with something like _cache_luarocks_. > print user_config_path=$user_config_path > ${cache_dir}/luarocks_configs_paths > print system_config_path=$system_config_path >> ${cache_dir}/luarocks_configs_paths You might need to quote the values with ${(qq)user_config_path} in case they have spaces in their values. By using braces around the print statements only one redirection will be needed instead of the redirection and append: { print ...; print ... } > cache > local where_luarocks=$(where luarocks) Use $commands[luarocks] rather than where in a command substitution. Command substitution typically requires a forked subshell which will be less efficient. > # luarocks_configured_values > local configured_lua_version configured_user_tree configured_system_tree > # luarocks_configs_paths > local config > if [[ -e ${cache_dir}/luarocks_configs_paths ]]; then > if [ ${where_luarocks} -nt ${cache_dir}/luarocks_configs_paths ]; then It is generally better to use [[ ... ]] for all conditions unless you're writing a script targeted at /bin/sh – which is not the case here. > if [[ -f ${user_manifest_file} ]] || [[ -f ${system_manifest_file} ]]; then > if [[ -f ${cache_file} ]]; then > # if either one of the manifest files is newer then the cache: > if [ ${user_manifest_file} -nt ${cache_file} ] || [ ${system_manifest_file} -nt ${cache_file} ]; then > (( 1 )) > else > (( 0 )) > fi > else > (( 1 )) > fi > else > (( 1 )) > fi I find this (( 1 )) stuff confusing. If I'm not mistaken the whole thing is equivalent to: [[ ( ! -f ${user_manifest_file} && ! -f ${system_manifest_file} ) || ! -f ${cache_file} || ${user_manifest_file} -nt ${cache_file} || ${system_manifest_file} -nt ${cache_file} ]] As for the logic, I'd mainly question what happens when one but not both of the manifest files is found to not exist. Note that && and || can be used inside [[ ... ]]. Oliver