zsh-workers
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: zsh-workers@zsh.org
Subject: Re: Slowdown around 5.0.5-dev-0
Date: Fri, 23 Oct 2015 08:32:33 +0200	[thread overview]
Message-ID: <CAKc7PVBC+MPN+EaRQni89PCH-AJk0X40wu5+eP1P3vqQhG6w7g@mail.gmail.com> (raw)
In-Reply-To: <CAKc7PVDk8sqOMcMsbxw78auCZqqoFBvma_d3hsm-KPpGoCFy5A@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2540 bytes --]

I ran the performance tests again with script formatting them
differently – they are aggregated on test function, not on zsh
version. This allows easier interpretation. A new conclusion is that
zhalloc patch doesn't help for string_test. So the first patch (36834)
speeds up string operations and also introduces increased memory
usage.

Best regards,
Sebastian Gniazdowski

On 22 October 2015 at 14:49, Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
> On 19 October 2015 at 19:21, Bart Schaefer <schaefer@brasslantern.com> wrote:
>> We leave that empty arena at the end, but then on the next zhalloc()
>> it's still not big enough, so another one gets allocated.
>>
>> You could try removing that "else" to let the trailing block be freed
>> again, but then we're back to needing to compare speed as well as space
>> across shell versions.
>
> I removed the else, code works longer and memory is still allocated.
> This is seen in mem-test3.txt, where there are many samples and large
> numbers, and in perf-test.txt, where there noted is long running time
> (numbers are milliseconds)
>
> I wrote perf-test.zsh to automatically perform performance tests:
> https://github.com/psprint/zsh-tools/
>
> With it and with mem-test.zsh I tested following zsh variants:
> - 5.0.2 osx
> - newheaps patch (zsh-newheaps-only)
> - newheaps and zhalloc patch 36836 (zsh-newheaps-zhalloc)
> - zhalloc and the previous patch 36834 (zsh-head-both-patches)
> - all three patches (zsh-newheaps-three-patches)
> - a 5.1.1-dev-0 clean zsh
> - the empty arena else removed
>
> My conclusions:
> - 36834 introduces high memory usage; I would suggest to use only two
> optimizations – newheaps and zhalloc; my znavtools are instant fast
> with them, what's slower is searching (wrote search_test function,
> results attached); basically half of pattern search speedup is lost
> with 36834, however what's gained is beautiful memory usage, without
> firefox-like values for RES (~700 MB); newheaps is responsible for
> instant-responsivity of my script, 36836 for much faster searching –
> that's a good compromise
>
> - searching with patterns through very large arrays (700k) allocates
> 264 MB of memory regardless of zsh version; this probably tells
> something
>
> - still not sure why 36834 allocates much memory for the string test
>
> - newheaps makes function calls longer, but it's not a substantial
> difference – 21196 ms vs. 18549 ms
>
> Best regards,
> Sebastian Gniazdowski

[-- Attachment #2: perf-test2.txt --]
[-- Type: text/plain, Size: 1880 bytes --]

Running [zsh-empty-arena-else]:          string_test      24933,14
Running [zsh-newheaps-zhalloc]:          string_test      10045,79
Running [zsh-newheaps-only]:             string_test      10053,55
Running [zsh-5.0.2-osx]:                 string_test       9726,88
Running [zsh-head-both-patches]:         string_test       4204,30
Running [zsh-newheaps-three-patches]:    string_test       4406,47
Running [zsh-5.1.1-dev-0-clean]:         string_test       9600,21

Running [zsh-empty-arena-else]:          array_test       12689,70
Running [zsh-newheaps-zhalloc]:          array_test       12042,77
Running [zsh-newheaps-only]:             array_test       11985,55
Running [zsh-5.0.2-osx]:                 array_test       12206,27
Running [zsh-head-both-patches]:         array_test       12320,56
Running [zsh-newheaps-three-patches]:    array_test       11788,41
Running [zsh-5.1.1-dev-0-clean]:         array_test       12814,19

Running [zsh-empty-arena-else]:          function_test    21774,49
Running [zsh-newheaps-zhalloc]:          function_test    21981,39
Running [zsh-newheaps-only]:             function_test    21268,29
Running [zsh-5.0.2-osx]:                 function_test    18539,70
Running [zsh-head-both-patches]:         function_test    18774,33
Running [zsh-newheaps-three-patches]:    function_test    21171,02
Running [zsh-5.1.1-dev-0-clean]:         function_test    18940,36

Running [zsh-empty-arena-else]:          search_test       3934,60
Running [zsh-newheaps-zhalloc]:          search_test       7007,60
Running [zsh-newheaps-only]:             search_test      11653,22
Running [zsh-5.0.2-osx]:                 search_test      11136,82
Running [zsh-head-both-patches]:         search_test       3872,39
Running [zsh-newheaps-three-patches]:    search_test       3960,67
Running [zsh-5.1.1-dev-0-clean]:         search_test      11281,82


[-- Attachment #3: perf-test.zsh --]
[-- Type: application/octet-stream, Size: 2219 bytes --]

#!/bin/zsh

emulate -L zsh
setopt extendedglob

zmodload zsh/zprof

zshs=( zsh-empty-arena-else zsh-newheaps-zhalloc zsh-newheaps-only )
zshs+=( zsh-5.0.2-osx zsh-head-both-patches zsh-newheaps-three-patches zsh-5.1.1-dev-0-clean )

#
# Children administration
#

trap "finished" SIGUSR1

finished() {
    FINISHED=1
}

# Waits for signal from child process
wait_for_end_of_test() {
    while [ "$FINISHED" -eq 0 ]; do
        sleep 1
    done
    kill -15 "$SUB_PID"
}

_finished_signal_wait() {
    kill -SIGUSR1 "$MAIN_PID"
    sleep 60
}

#
# Tests
#

tests=( string_test array_test function_test search_test )

float multiplier=0.5

string_test() {
    local a=""
    integer i=$(( 150000*multiplier ))
    repeat $i; do a+="$i"; done
}

array_test() {
    typeset -a a
    integer i=$(( 25000*multiplier ))
    repeat $i; do a+=( $i ); done
}

function_test() {
    local count
    integer i=$(( 10000*multiplier ))

    if [ -z "$1" ]; then
        repeat $i; do function_test 100; done
    else
        count="$1"
    fi

    if (( count -- > 0 )); then
        function_test "$count"
    fi
}

search_test() {
    integer elements=$(( 800000 * multiplier ))
    a="${(r:elements:: _:)b}"
    a=( $=a )
    a=( "${(@M)a:#(#i)*_*}" )
    a=( "${(@)a//(#mi)(_|a)/-${MATCH}-}" )
    a=( "${(@)a//(#bi)(_|-)/|${match[1]}|}" )
}

#
# Main code
#

# Detect main vs. for-test invocation
if [ -z "$1" ]; then

    for test in "$tests[@]"; do
        for current_zsh in "$zshs[@]"; do

            type "$current_zsh" 2>/dev/null 1>&2 || { echo >&2 "Skipping non-accessible $current_zsh"; continue }
            zsh_binary="${current_zsh##*/}"
            FINISHED=0
            TEST="$test"

            "$current_zsh" -c "source ./$0 $$ \"$current_zsh\" $test" &

            SUB_PID=$!
            wait_for_end_of_test
        done

        echo

    done

else
    MAIN_PID="$1"
    zsh_binary="${2##*/}"
    shift
    shift
    txt="Running [$zsh_binary]: "
    echo -n "${(r:40:: :)txt}" "${(r:15:: :)*}"

    # Run the test
    zprof -c
    "$@"
    zprof_out=( "${(@f)"$( zprof )"}" )
    zprof_out="$zprof_out[3]"
    zprof_out=( $=zprof_out )
    echo "${(l:10:: :)zprof_out[3]}"

    _finished_signal_wait
fi

  parent reply	other threads:[~2015-10-23  6:32 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-10 10:54 Sebastian Gniazdowski
2015-10-10 17:58 ` Bart Schaefer
2015-10-10 18:11   ` Sebastian Gniazdowski
2015-10-10 18:32     ` Sebastian Gniazdowski
2015-10-11  0:06       ` Bart Schaefer
2015-10-11  6:20         ` Bart Schaefer
2015-10-11  8:39           ` Sebastian Gniazdowski
2015-10-11 16:17             ` Bart Schaefer
2015-10-11 16:48               ` Sebastian Gniazdowski
2015-10-11 17:31                 ` Bart Schaefer
2015-10-11 18:05                   ` Sebastian Gniazdowski
2015-10-11 21:22                     ` Bart Schaefer
2015-10-12  8:21                       ` Sebastian Gniazdowski
2015-10-12 14:01                         ` Bart Schaefer
2015-10-12 16:50                           ` Sebastian Gniazdowski
2015-10-13  0:33                             ` Bart Schaefer
2015-10-13  8:21                               ` Sebastian Gniazdowski
2015-10-13 15:52                                 ` Bart Schaefer
2015-10-14  6:50                                   ` Sebastian Gniazdowski
2015-10-14 13:27                                   ` Peter Stephenson
2015-10-14 16:25                                     ` Bart Schaefer
2015-10-14 16:50                                       ` Bart Schaefer
2015-10-15  4:32                                         ` Bart Schaefer
2015-10-15 13:03                                           ` Sebastian Gniazdowski
2015-10-16  0:35                                             ` Bart Schaefer
2015-10-17  9:12                                               ` Sebastian Gniazdowski
2015-10-17  9:24                                                 ` Sebastian Gniazdowski
2015-10-18 16:19                                                 ` Bart Schaefer
2015-10-18 20:40                                                   ` Sebastian Gniazdowski
2015-10-18 21:07                                                     ` Bart Schaefer
2015-10-18 21:31                                                       ` Sebastian Gniazdowski
2015-10-19 17:21                                                         ` Bart Schaefer
2015-10-22 12:49                                                           ` Sebastian Gniazdowski
2015-10-22 15:00                                                             ` Bart Schaefer
2015-10-22 16:28                                                               ` Sebastian Gniazdowski
2015-10-22 16:33                                                                 ` Sebastian Gniazdowski
2015-10-23 15:40                                                               ` Sebastian Gniazdowski
2015-10-23 15:57                                                                 ` Sebastian Gniazdowski
2015-10-23 19:26                                                                   ` Bart Schaefer
2015-10-23 23:50                                                                     ` Bart Schaefer
2015-10-24  6:09                                                                       ` Sebastian Gniazdowski
2015-10-24  7:37                                                                         ` Sebastian Gniazdowski
2015-10-24  8:04                                                                           ` Sebastian Gniazdowski
2015-10-24 19:39                                                                           ` Bart Schaefer
2015-10-25  7:35                                                                             ` Sebastian Gniazdowski
2015-10-25 17:23                                                                               ` Bart Schaefer
2015-10-25 20:56                                                                                 ` Sebastian Gniazdowski
2015-10-26  0:49                                                                                   ` Bart Schaefer
2015-10-26  7:41                                                                                     ` Sebastian Gniazdowski
2015-10-26  7:47                                                                                       ` Sebastian Gniazdowski
2015-10-24  6:27                                                                       ` Sebastian Gniazdowski
2015-10-24 10:54                                                                       ` Sebastian Gniazdowski
2015-10-24 11:25                                                                         ` Sebastian Gniazdowski
2015-10-24 16:31                                                                         ` Bart Schaefer
2015-10-24 16:41                                                                           ` Bart Schaefer
2015-10-23  6:32                                                             ` Sebastian Gniazdowski [this message]
2015-10-16  0:37                                             ` Bart Schaefer
2015-10-13 13:07                         ` Sebastian Gniazdowski
2015-10-13 13:31                           ` Sebastian Gniazdowski
2015-10-12 12:05                       ` Sebastian Gniazdowski
2015-10-12 15:13                         ` Bart Schaefer

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=CAKc7PVBC+MPN+EaRQni89PCH-AJk0X40wu5+eP1P3vqQhG6w7g@mail.gmail.com \
    --to=sgniazdowski@gmail.com \
    --cc=zsh-workers@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).