From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 4600 invoked from network); 27 Nov 2021 08:34:26 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 27 Nov 2021 08:34:26 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1638002066; b=qtcR3z1GZoiLdKJjp+KGWpcnAzZ2Vuu0rB4VlNvBLKg4Xsqk9R3YiVS5ytkSc0Av1ARvQkLAjd 1ADifSMhQp8ftQflJF4fCWyoMk27c97KxP7DbN6cZ/dvssP+d8+DfPrHTtYm/gHn/A+HTq6E8j qwXCJEdAoYZzrKaJoPXNb8EkMo0G9QnGj187iO2j5eaVzokIQxIlW1asZhuojTh9T/+oaVJOwH pycFpwzOlnVP0g7UN1Bf9xBsiA/dNYLmJxwr57Wp5NSMpye11pmBxFFjHJ2K2qyV9rX2M7xM1Q kQZMixp8bqi3B84MVZ4D6ug9YxNGGO9PnVrMQEwd+pmIPQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-qv1-f46.google.com) smtp.remote-ip=209.85.219.46; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1638002066; bh=TVYmXqYgOtSzUjmHdVUsRW1LXj87PrPswu0XOZMqHe0=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=f3DXzD9IFTecePY3KHt3IhoyMOarXyH7J+OcYO87kkm9bq/g05DgO2EB0AnmJCK2lJ+Cfe4WYi 1TPveKfqLVPS8U7vlby2k1/WsQht49804z3gXzjO2134tQF3Go8cCTcSGoEF5tQ8nggZKMfULx BIM9w6Lou8W5IxSzzf68ztFZcDTw6csOxbo+jqCHuJoC9+iqZ5ukfJdoLGk1C42pmjYx4OQA/j W6xB3Y4tF5boF/8VOjBGDhFwSxTvBoSqExXMpT/kP007iRj2G4T+qYBzxx+Y8xaAbBgTvQFBmd fR6eRADEMCnLUziMJuSrBBksXvcNM4Yl/rI2rLaUcMqJvQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=TVYmXqYgOtSzUjmHdVUsRW1LXj87PrPswu0XOZMqHe0=; b=bZDEqEw+zxfM4LXgMCeqJs94Z/ Dx8joh1tnylp/1TGg7UtvHXEGhi6Dp5eX6oDJajwNhpEkk9mF+R8RVd6PRoJJ8ZVhzOiJY3XxYPbP 9IxNf4iQlMJO2SBFYcJQ6J4MmPAC/QBh5RD+ssysKfCjA7/FfWp0NBA6Mj7jxiP3cA3y2z5+wuyVp nyTR4js7x5Gejr4z4fsVgfo623LVmemNbG1Aa6dWv1PK7ZVAdth6eG9TkqvbofISWHGR2qYkz5hcr 6fkXF3IpO82kUUhnSbuCXWUBYtCOENhMv4jje43u2rWXDixUDvvb9Xu240iyA0OU2xICP29iJnp7C eR8wvxJg==; Received: from authenticated user by zero.zsh.org with local id 1mqtAA-0003I1-5Q; Sat, 27 Nov 2021 08:34:26 +0000 Authentication-Results: zsh.org; iprev=pass (mail-qv1-f46.google.com) smtp.remote-ip=209.85.219.46; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-qv1-f46.google.com ([209.85.219.46]:38533) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1mqt9M-0002Y8-5J; Sat, 27 Nov 2021 08:33:36 +0000 Received: by mail-qv1-f46.google.com with SMTP id a24so9171787qvb.5 for ; Sat, 27 Nov 2021 00:33:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TVYmXqYgOtSzUjmHdVUsRW1LXj87PrPswu0XOZMqHe0=; b=Gd5J8WtqlwYNgOm1/vdfP9OqhO8eX/pgDbboLXSPrpc5umVY0RwePsciYr8dnCKEEK /QrZxMwVmQS0SKB4CkbFBl91IR1TxMKd4zbgpRVSJST7vDytBdOOLejy7T89G9GXWwKw 07TUpbqxSirejEjMOMzf2Ds0haIFkdv2RJ2OMZERkDNXjayekBPgHWhrbUv3H/gAG4z8 hjAONax8+98zYuP8eRoMGpB91kIu5ZX6RxewbUsn7M+g39fRJ7YGXTFZmHhu0aZsmABR WXHtchzRSSQAfHpI0vQUrQVuPBI/z7Dh9RRC7SPnD7i/5tzGdq9kVdQt/aIcNoxw7pzN aOSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TVYmXqYgOtSzUjmHdVUsRW1LXj87PrPswu0XOZMqHe0=; b=C57NWLd1FN89jhmNtoj6U02Sl9Id7E5A2E6a5gxuJIrQlTwv7DJcoFDOKOHN+1ijOA 3fWB5nvoDwR1GnAoeXLOcHxkVXtzCJMCCJSzIMCaEPZJkzY5KeyW2o69BnTn4D1NsFnI Y303Ry2zI5DnTFegFmXqGT0K6Je0QIna2a1WP9DPasWcUEPD0C3f3XQJPsKuE+TECFaU JXknZ4yMATg7rdF6xDaudOYWahEACdf9iacNYFB10wptLePFeNocbg6hwFJ4Lg0VlSaT hzBv4cAU4jrvV+JMLRT/jCa3TmPOP1N65kDAQVknaeQGN2OnShqhrjdEwS7FiVYJth+t QVYw== X-Gm-Message-State: AOAM532kFOKaUDihpsFviTVTLZcYYCD/O8o/ZpDlhZXGCXcIW2BwqduB 5DHNRWQ5cZJmT+mXyUfoo24k/MdENWkynqqPPRrEcrhLyFg= X-Google-Smtp-Source: ABdhPJy1mD1ZRPU6yhnSYqZuxiDMLx8Rq0ZNG3twWWV295POkO9OQZAoHaMDe/7LrmDUjX0fr9WwBOrZIEZvUKTRq/E= X-Received: by 2002:a05:6214:528a:: with SMTP id kj10mr17204319qvb.72.1638002014774; Sat, 27 Nov 2021 00:33:34 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Roman Perepelitsa Date: Sat, 27 Nov 2021 09:33:25 +0100 Message-ID: Subject: Re: Shell startup, aliases vs. functions vs. autoloadable functions, and zcompile benefits To: Zach Riggle Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 27369 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On Sat, Nov 27, 2021 at 9:11 AM Zach Riggle wrote: > > Does anybody have information on which approach is faster? > > alias foo='foo --flag1 --flag2' > foo() { command foo --flag1 --flag2 "$@" } > autoloadable module containing (2) In theory the first and the last should have the same performance and the middle should be slower because it has to parse the body. In practice you won't find any difference: zsh parser is very fast. There is a difference in usability between these options. When using an alias, you can expand it (provided that you have a binding for expanding aliases) to check what it does and then either undo the expansion (provided you have a binding) or modify it. I do this all the time. Aliases also allow you to bypass them with `\foo` rather than `command foo`. Less typing. > Finally, I'm aware of the zcompile tool to create .zwc bytecode files, but it appears that this causes issues with $functions / $functions_source and sometimes things don't work. zcompiling has two main gotchas: 1. Aliases get expanded differently. 2. If you move a source file (e.g., to backup) and then move it back (restore from backup), you might end up with a mismatched zwc with greater mtime. See https://github.com/romkatv/zsh-bench#cutting-corners for a more detailed description. > Is there a true performance benefit in the general case for pre-compiling ALL of my zsh scripts (i.e. everything inside ~/.zprezto that /usr/bin/file says is a "zsh script text executable")? The only benefit of zcompiling is performance. For autoloadable functions that don't get invoked on startup you won't be able to tell the difference. This means that the only benefit of zcompiling is faster zsh startup. You can simply try it: zcompile your stuff and see if you can tell the difference in zsh startup speed using your own senses. If you cannot, there is no point in zcompiling. If you want a machine-mediated measurement, you can use https://github.com/romkatv/zsh-bench and look at first_prompt_lag and first_command_lag in the output. Roman.