Fix performance degradation introduced by the second expansion feature.

I did this by adding intelligence into the algorithm such that the
second expansion was only actually performed when the prerequisite list
contained at least one "$", so we knew it is actually needed.

Without this we were using up a LOT more memory, since every single
target (even ones never used by make) had their file variables
initialized.  This also used a lot more CPU, since we needed to create
and populate a new variable hash table for every target.

There is one issue remaining with this feature: it leaks memory.  In
pattern_search() we now initialize the file variables for every pattern
target, which allocates a hash table, etc.  However, sometimes we
recursively invoke pattern_search() (for intermediate files) with an
automatic variable (alloca() I believe) as the file.  When that function
returns, obviously, the file variable hash memory is lost.
This commit is contained in:
Paul Smith
2005-04-13 03:16:33 +00:00
parent 3daf8df6ee
commit 49ee105c68
7 changed files with 117 additions and 58 deletions

View File

@@ -1,3 +1,30 @@
2005-04-12 Paul D. Smith <psmith@gnu.org>
The second expansion feature causes significant slowdown. Timing
a complex makefile (GCC 4.1) shows a slowdown from .25s to just
read the makefile before the feature, to 11+s to do the same
operations after the feature. Additionally, memory usage
increased drastically. To fix this I added some intelligence that
avoids the overhead of the second expansion unless it's required.
* dep.h: Add a new boolean field, need_2nd_expansion.
* read.c (eval): When creating the struct dep for the target,
check if the name contains a "$"; if so set need_2nd_expansion to 1.
(record_files): If there's a "%" in a static pattern rule, it gets
converted to "$*" so set need_2nd_expansion to 1.
* file.c (expand_deps): Rework to be more efficient. Only perform
initialize_file_variables(), set_file_variables(), and
variable_expand_for_file() if the need_2nd_expansion is set.
* implicit.c (pattern_search): Default need_2nd_expansion to 0.
(pattern_search): Ditto.
* main.c (handle_non_switch_argument): Ditto.
(main): Ditto.
* read.c (read_all_makefiles): Ditto.
(eval_makefile): Ditto.
2005-04-07 Paul D. Smith <psmith@gnu.org>
* main.c (main) [WINDOWS32]: Export PATH to sub-shells, not Path.