* Single-run while makes script fast
@ 2015-12-04 16:20 Sebastian Gniazdowski
2015-12-04 17:33 ` Sebastian Gniazdowski
2015-12-04 17:43 ` Bart Schaefer
0 siblings, 2 replies; 5+ messages in thread
From: Sebastian Gniazdowski @ 2015-12-04 16:20 UTC (permalink / raw)
To: Zsh hackers list
[-- Attachment #1: Type: text/plain, Size: 764 bytes --]
Hello,
I attach animated gif showing the effect. The while loop in following
code makes whole script fast:
loop=1
while (( loop -- )); do
filename="lsoflsof" # 89k elements
body=( "${(@f)"$(<"$filename" )"}" )
done
Commenting out the loop and leaving only its body makes the whole script slow:
loop=1
#while (( loop -- )); do
filename="lsoflsof" # 89k elements
body=( "${(@f)"$(<"$filename" )"}" )
#done
This is reveals on Zsh 5.0.8 (OS X). On 5.2 it isn't visible or
doesn't actually occur – because of recent optimizations.
I wasn't able to reproduce this in some short script, but might yet
try to do this. I'm reporting because maybe there is something hidden
behind this.
Best regards,
Sebastian Gniazdowski
[-- Attachment #2: while.gif --]
[-- Type: image/gif, Size: 226679 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Single-run while makes script fast
2015-12-04 16:20 Single-run while makes script fast Sebastian Gniazdowski
@ 2015-12-04 17:33 ` Sebastian Gniazdowski
2015-12-04 17:43 ` Bart Schaefer
1 sibling, 0 replies; 5+ messages in thread
From: Sebastian Gniazdowski @ 2015-12-04 17:33 UTC (permalink / raw)
To: Zsh hackers list
I tested this on my two other scripts and it's speeding things up also
there. Already commited the "optimizations":
https://github.com/psprint/zsh-navigation-tools/commit/71fe5a2227a4e8a116878194bf2bbb6db1bb8c25
Best regards,
Sebastian Gniazdowski
On 4 December 2015 at 17:20, Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
> Hello,
> I attach animated gif showing the effect. The while loop in following
> code makes whole script fast:
>
> loop=1
> while (( loop -- )); do
> filename="lsoflsof" # 89k elements
> body=( "${(@f)"$(<"$filename" )"}" )
> done
>
> Commenting out the loop and leaving only its body makes the whole script slow:
>
> loop=1
> #while (( loop -- )); do
> filename="lsoflsof" # 89k elements
> body=( "${(@f)"$(<"$filename" )"}" )
> #done
>
> This is reveals on Zsh 5.0.8 (OS X). On 5.2 it isn't visible or
> doesn't actually occur – because of recent optimizations.
>
> I wasn't able to reproduce this in some short script, but might yet
> try to do this. I'm reporting because maybe there is something hidden
> behind this.
>
> Best regards,
> Sebastian Gniazdowski
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Single-run while makes script fast
2015-12-04 16:20 Single-run while makes script fast Sebastian Gniazdowski
2015-12-04 17:33 ` Sebastian Gniazdowski
@ 2015-12-04 17:43 ` Bart Schaefer
2015-12-04 18:01 ` Peter Stephenson
2015-12-04 18:27 ` Sebastian Gniazdowski
1 sibling, 2 replies; 5+ messages in thread
From: Bart Schaefer @ 2015-12-04 17:43 UTC (permalink / raw)
To: Zsh hackers list
On Dec 4, 5:20pm, Sebastian Gniazdowski wrote:
}
} I attach animated gif showing the effect. The while loop in following
} code makes whole script fast:
By code examination rather than actual experiment --
The difference when the while-loop is introduced is that the entire
heap allocated by body=(...) is discarded with a single popheap() at
the "done", whereas without the loop the space is reclaimed by a call
to freeheap() which has to examine every heap arena.
You should be able to get the same effect with "repeat 1" so as not
to need the loop-counter variable.
This might indicate that the exec*() routines in Src/loop.c are not
doing as much as they could to keep memory footprint to its minimum.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Single-run while makes script fast
2015-12-04 17:43 ` Bart Schaefer
@ 2015-12-04 18:01 ` Peter Stephenson
2015-12-04 18:27 ` Sebastian Gniazdowski
1 sibling, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2015-12-04 18:01 UTC (permalink / raw)
To: Zsh hackers list
On Fri, 04 Dec 2015 09:43:31 -0800
Bart Schaefer <schaefer@brasslantern.com> wrote:
> This might indicate that the exec*() routines in Src/loop.c are not
> doing as much as they could to keep memory footprint to its minimum.
You might have thought there ought to be some heap arrangement around
execlist() and/or execpline().
pws
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Single-run while makes script fast
2015-12-04 17:43 ` Bart Schaefer
2015-12-04 18:01 ` Peter Stephenson
@ 2015-12-04 18:27 ` Sebastian Gniazdowski
1 sibling, 0 replies; 5+ messages in thread
From: Sebastian Gniazdowski @ 2015-12-04 18:27 UTC (permalink / raw)
To: Zsh hackers list
On 4 December 2015 at 18:43, Bart Schaefer <schaefer@brasslantern.com> wrote:
> You should be able to get the same effect with "repeat 1" so as not
> to need the loop-counter variable.
Thanks for the tip, checked – repeat 1 has the same benefits
Best regards,
Sebastian Gniazdowski
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-12-04 18:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-04 16:20 Single-run while makes script fast Sebastian Gniazdowski
2015-12-04 17:33 ` Sebastian Gniazdowski
2015-12-04 17:43 ` Bart Schaefer
2015-12-04 18:01 ` Peter Stephenson
2015-12-04 18:27 ` Sebastian Gniazdowski
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).