bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Surprising results when profiling Bash


From: Chet Ramey
Subject: Re: Surprising results when profiling Bash
Date: Wed, 28 Aug 2024 09:58:53 -0400
User-agent: Mozilla Thunderbird

On 8/24/24 1:46 PM, Martin D Kealey wrote:
I've been making some tentative patches to the `devel` branch, and since I
have a fairly large bashrc, when I compile Bash with maximal debugging
support, its startup is ... underwhelmingly slothful.

You're seeing the memory tracing and debugging code.


So I decided to build it with profiling enabled, and see if I'd done
something to ruin its performance. (Short answer: nope.)

What stood out immediately is that 50%~90% of the time is spent in
mregister_free(). In theory gprof separates the time spent in subordinate
function calls, but there's no reporting of find_entry(), perhaps because
it's 'static', and therefore in-lined, so perhaps that's the real culprit.

What puzzles me is that this is much more than mregister_alloc(), during a
phase when *most* of the activity is defining new stuff rather than getting
rid of stuff.

It's a simple table; alloc only has to find an empty slot, while free has
to potentially search for a while to find the associated alloc.


I haven't tweaked anything in this area of the code.

Is this expected behaviour?
Do I need to change my compilation options, or make any other changes?

If you don't want it, compile without MALLOC_DEBUG defined. That's what
release versions do.


I haven't delved very deeply into this code, but it does seem to be
preoccupied with managing signals, presumably because the code isn't
re-entrant; so I'm wondering if it would be worthwhile to investigate
different kinds of allocators, or perhaps a different approach to handling
signals?

It only blocks signals if it's running from a trap handler or SIGINT or
SIGCHLD are trapped. Mostly legacy stuff from when SIGINT traps were
handled immediately.

--
``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/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]