zsh-users
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Sebastian Gniazdowski <psprint@zdharma.org>
Cc: zsh-users@zsh.org
Subject: Re: Why sourcing a file is not faster than doing a loop with eval, zle -N
Date: Mon, 19 Jun 2017 13:24:13 +0100	[thread overview]
Message-ID: <20170619122413.GA9294@chaz.gmail.com> (raw)
In-Reply-To: <etPan.594513a8.516100cd.10b2e__10513.1716504276$1497699329$gmane$org@zdharma.org>

Note:

$ time zsh -c 'repeat 100 . ./fsh_cache'
[...]
./fsh_cache:zle:269: invalid widget `.menu-select'
./fsh_cache:zle:269: invalid widget `.menu-select'
zsh -c 'repeat 100 . ../hacking-private/FSH/fsh_cache'  1.13s user 0.98s system 99% cpu 2.109 total

A lot of "system" time.

$ wc ./fsh_cache
  554  2964 58524 ./fsh_cache

$ strace -c  zsh -c '. ./fsh_cache'
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
100.00    0.000996           0     60022           rt_sigprocmask


60022 calls to rt_sigprocmask sounds a bit much. They  seem to be all on

#0  0x00007ffff730d730 in __sigprocmask (how=1, set=0x7fffffffb1c0, oset=0x7fffffffb120) at ../sysdeps/unix/sysv/linux/x86_64/sigprocmask.c:36
#1  0x000000000049b2c0 in signal_unblock (set=...) at signals.c:274
#2  0x00000000004580ac in shingetline () at input.c:148
#3  0x000000000045899b in inputline () at input.c:278
#4  0x000000000045882a in ingetc () at input.c:226
#5  0x000000000046211e in gettok () at lex.c:611
#6  0x000000000046183b in zshlex () at lex.c:275
#7  0x0000000000484825 in parse_event (endtok=37) at parse.c:569
#8  0x0000000000453f6e in loop (toplevel=0, justonce=0) at init.c:146
#9  0x0000000000456db0 in source (s=0x708930 "../hacking-private/FSH/fsh_cache") at init.c:1386
#10 0x0000000000425a0e in bin_dot (name=0x7ffff7ff2550 ".", argv=0x7ffff7ff25b0, ops=0x7fffffffd980, func=0) at builtin.c:5699
#11 0x00000000004105ff in execbuiltin (args=0x7ffff7ff2580, assigns=0x0, bn=0x6dc7c0 <builtins+384>) at builtin.c:485
#12 0x0000000000437fd4 in execcmd_exec (state=0x7fffffffe300, eparams=0x7fffffffdef0, input=0, output=0, how=18, last1=1) at exec.c:3958
#13 0x0000000000431a50 in execpline2 (state=0x7fffffffe300, pcode=131, how=18, input=0, output=0, last1=1) at exec.c:1873
#14 0x0000000000430665 in execpline (state=0x7fffffffe300, slcode=4098, how=18, last1=1) at exec.c:1602
#15 0x000000000042f95a in execlist (state=0x7fffffffe300, dont_change_job=0, exiting=1) at exec.c:1360
#16 0x000000000042efd4 in execode (p=0x7ffff7ff2488, dont_change_job=0, exiting=1, context=0x4c37a2 "cmdarg") at exec.c:1141
#17 0x000000000042ee9c in execstring (s=0x7fffffffe772 ". ../hacking-private/FSH/fsh_cache", dont_change_job=0, exiting=1,
    context=0x4c37a2 "cmdarg") at exec.c:1107
#18 0x0000000000456a61 in init_misc (cmd=0x7fffffffe772 ". ../hacking-private/FSH/fsh_cache", zsh_name=0x7fffffffe76a "zsh") at init.c:1292
#19 0x0000000000457e8e in zsh_main (argc=3, argv=0x7fffffffe4f8) at init.c:1678
#20 0x000000000040f7f6 in main (argc=3, argv=0x7fffffffe4f8) at ./main.c:93

Which probably explains why one gets about as many rt_sigprocmask calls as
there are bytes in the file.

$ time zsh -c 'repeat 100 eval  "$(<fsh_cache)"'

gives:

1.18s user 0.05s system 99% cpu 1.239 total

With "only" 942 rt_sigprocmask calls according to strace -c.

There's probably scope for optimisation here, though I can't
comment further as I don't know why that signal handling code is
there in the first place.

-- 
Stephane


       reply	other threads:[~2017-06-19 12:24 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <etPan.594513a8.516100cd.10b2e__10513.1716504276$1497699329$gmane$org@zdharma.org>
2017-06-19 12:24 ` Stephane Chazelas [this message]
2017-06-19 15:31   ` Bart Schaefer
     [not found]   ` <170619083116.ZM17323__41722.0601499595$1497886320$gmane$org@torch.brasslantern.com>
2017-06-19 16:16     ` Stephane Chazelas
2017-06-19 19:14       ` Bart Schaefer
2017-06-17 11:34 Sebastian Gniazdowski
     [not found] ` <CAH+w=7bVXtubcdwvEBC9isE32683dUipAUS=vrAkgO5pp2bkkw@mail.gmail.com>
     [not found]   ` <CAH+w=7afTi=1bfLBCmq8-vB-rLWDtEkAtk8gCCna3-mQwZ1-Ow@mail.gmail.com>
2017-06-17 14:05     ` Bart Schaefer
     [not found]     ` <etPan.594538f9.2ea629d6.10b2e@AirmailxGenerated.am>
2017-06-17 14:56       ` Sebastian Gniazdowski
2017-06-17 15:44         ` Sebastian Gniazdowski
2017-06-17 16:39           ` Bart Schaefer
2017-06-17 17:25             ` Sebastian Gniazdowski

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=20170619122413.GA9294@chaz.gmail.com \
    --to=stephane.chazelas@gmail.com \
    --cc=psprint@zdharma.org \
    --cc=zsh-users@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).