Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #14485 > unrolled thread
| Started by | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| First post | 2018-08-14 11:25 -0400 |
| Last post | 2018-08-14 23:21 +0100 |
| Articles | 2 — 2 participants |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Unexpected delay in using arguments. Chet Ramey <chet.ramey@case.edu> - 2018-08-14 11:25 -0400
Re: Unexpected delay in using arguments. Stephane Chazelas <stephane.chazelas@gmail.com> - 2018-08-14 23:21 +0100
| From | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| Date | 2018-08-14 11:25 -0400 |
| Subject | Re: Unexpected delay in using arguments. |
| Message-ID | <mailman.5096.1534260312.1292.bug-bash@gnu.org> |
On 8/12/18 3:16 AM, Bize Ma wrote:
> Try this script:
>
> #!/bin/bash
> TIMEFORMAT='%R'
>
> n=1000
> m=20000
>
> f1 () { :; }
>
> f2 () { i=0; time while [ "$((i+=1))" -lt "$n" ]; do : ; done
> i=0; time while [ "$((i+=1))" -lt "$n" ]; do f1 ; done
> }
>
> test1() { set -- $(seq $m)
> f2 ""
> f2 "$@"
> }
> test1
>
> To get:
>
> 0.019
> 0.028
> 0.019
> 19.204
>
> Which is a thousand times slower.
If you build a profiling version of bash, you'll find that about 75% of
that time is spent copying the list of arguments around, since you have
to save and restore it each time you call f1. Looking at making that more
efficient has been a low-level task for a while now.
> Bash 5 is even worse, try:
Bash-5.0-alpha is not a released version, so it uses the debugging malloc.
If you profile that, you'll find that about 99% of the time is spent
marking allocations as active and free in the table the bash malloc uses
to keep track of active memory.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
[toc] | [next] | [standalone]
| From | Stephane Chazelas <stephane.chazelas@gmail.com> |
|---|---|
| Date | 2018-08-14 23:21 +0100 |
| Message-ID | <mailman.5111.1534285326.1292.bug-bash@gnu.org> |
| In reply to | #14485 |
2018-08-14 11:25:04 -0400, Chet Ramey:
[...]
> If you build a profiling version of bash, you'll find that about 75% of
> that time is spent copying the list of arguments around, since you have
> to save and restore it each time you call f1. Looking at making that more
> efficient has been a low-level task for a while now.
[...]
To save and restore that list of arguments, you only need to
save and restore one pointer. I don't see why you'd need to copy
the full list of pointers let alone the text of the arguments.
Note that it makes scripts using functions and that receive a
large number of arguments (think of scripts called as find .
-exec myscript {} + for instance) terribly inefficient.
find / -xdev -exec bash -c 'f(){ :;}; for i do f; done' bash {} +
(do nothing in a function for all the files in my root file
system) takes 4 seconds in dash and 9 minutes (135 times as
much) in bash.
--
Stephane
[toc] | [prev] | [standalone]
Back to top | Article view | gnu.bash.bug
csiph-web