Home | History | Annotate | Download | only in make
History log of /src/usr.bin/make/str.h
RevisionDateAuthorComments
 1.20  07-Jul-2024  rillig make: only generate code for cleanup functions in CLEANUP mode
 1.19  05-Jan-2024  rillig make: clean up string functions

No binary change.
 1.18  05-Jan-2024  rillig make: inline Substring_Sub

Remove redundant assertions.
 1.17  23-Jun-2023  rillig make: warn about malformed patterns in ':M', ':N' and '.if make(...)'

These patterns shouldn't occur in practice, as their results are tricky
to predict. Generate a warning for now, and maybe an error later.

Reviewed by sjg@.
 1.16  05-Dec-2022  rillig make: inline LazyBuf_AddBytesBetween

No binary change.
 1.15  15-Dec-2021  rillig make: in CLEANUP mode, free interned strings at the very end

Noticed by sjg.
 1.14  13-Dec-2021  rillig make: fix memory leak for filenames in .for loops (since 2013-06-18)

Previously, each time a .for directive pushed its buffer on the input
file stack, the current filename was duplicated. This was a waste of
memory.

The name of a file is typically only used while it is read in. There is
one situation when the filename is needed for longer, which is when a
target is defined.

Since .for loops are implemented as a special form of included files,
each .for loop duplicated the current filename as well.

$ cat << EOF > for.mk
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.for i in 1 2 3 4 5 6 7 8 9 0
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor
.endfor

all:
@ps -o rsz -p ${.MAKE.PID}
EOF

$ make-2021.12.13.03.55.16 -r -f for.mk
RSZ
10720

$ ./make -r -f for.mk
RSZ
1716

The difference is 8 MB, which amounts to 1 million .for loops.
 1.13  12-Dec-2021  rillig make: remove unused type MFStr

The only binary change is the line number of the assertion in
Substring_Sub.
 1.12  12-Dec-2021  rillig make: fix memory leak in LazyBuf

This affects many operations on variable expressions. Those using
LazyBuf_Done are affected, those using LazyBuf_DoneGet aren't.

$ cat <<'EOF' > lazybuf-memleak.mk
.for i in ${:U:range=5}
. for j in ${:U:range=1000}
. for k in ${:U:range=1000}
. if 0 && ${VAR:Dpattern\: that needs unescaping}
. endif
. endfor
. endfor
.endfor

all:
@ps -o vsz -p ${.MAKE.PID} | sed 1d
EOF

Before using LazyBuf for the modifier ':D':

$ make-2021.04.14.16.12.26 -r -f lazybuf-memleak.mk
VSZ RSZ
1357136 1336432

Using LazyBuf for the modifier ':D':

$ make-2021.04.14.16.59.34 -r -f lazybuf-memleak.mk
VSZ RSZ
1590864 1574164

This commit alone allocates around 150 MB more data, which matches
5_000_000 strings * 30 bytes/string.

It looks very wrong that the above simple makefile uses 1.3 GB of RAM at
all, and it had already done this in 2017, long before LazyBuf was
introduced. Before 2017.01.30.02.46.20, the above test makefile reports
way smaller numbers, but that's because the modifier ':range' did not
exist back then.
 1.11  05-Dec-2021  rillig make: save a memory allocation in each modifier ':O' and ':u'

No functional change.
 1.10  05-Dec-2021  rillig make: inline Str_Words into .for loop handling

This saves one memory allocation and a bit of copying, per .for loop.

No functional change.
 1.9  30-May-2021  rillig make: inline str_concat4

This function is only ever used for forming strings of the form
"archive(member)".

No functional change.
 1.8  14-Apr-2021  rillig branches: 1.8.2;
make: let the compiler decide whether to inline string functions

On x86_64, this reduces the binary size by 2 kB.
 1.7  14-Apr-2021  rillig make: reduce memory allocations in the modifiers ':D' and ':U'
 1.6  12-Apr-2021  rillig make: reduce memory allocation and strlen calls in modifier ':from=to'

Previously, SysVMatch was quite verbose and felt like hand-optimized
assembler code, which made it difficult to discover the underlying idea
of the code.

All this code was replaced with two simple calls to Substring_HasPrefix
and Substring_HasSuffix. Now that the operands of that modifier are no
longer passed as C strings, there is no need to collect all information
in a single scan through the word and the pattern.

It was not necessary to call Var_Subst unconditionally. Calling it only
when the string contains a '$' saves another memory allocation and two
string copies (because of the Buf_DoneDataCompact).

No functional change.
 1.5  11-Apr-2021  rillig make: improve performance for LazyBuf

The previous O(n^2) time complexity for parsing a long string with many
variable expressions was not meant to last for long. I had hoped to fix
it within a few minutes, but that will take more time.

For now, make LazyBuf simpler by using a traditional C string for the
expected part instead of a Substring. This avoids a strlen call per
Var_Parse.

No functional change, only performance.
 1.4  11-Apr-2021  rillig make: migrate ParseModifierPart to use Substring

This will reduce memory allocation for modifier parts without the escape
characters '$' or '\'.

No functional change.
 1.3  11-Apr-2021  rillig make: avoid unnecessary calls to strlen when evaluating modifiers

No functional change.
 1.2  11-Apr-2021  rillig make: migrate ModifyWord functions to use Substring

This benefits the modifiers ':T' and ':H' since these scan the word from
the end. The SysV modifier '.c=.o' does not benefit yet, this will be
done in a follow-up commit.

Currently ModifyWords calls strlen for each single word, which degrades
performance. This will be cleaned up in a follow-up commit as well.

No functional change.
 1.1  11-Apr-2021  rillig make: add types Substring and LazyBuf

These will be used for making the string handling more efficient,
avoiding allocations, especially when evaluating variable expressions.

Since the string handling has grown quite a bit in the last months,
extract it into its own header file.

No functional change.
 1.8.2.1  31-May-2021  cjep sync with head

RSS XML Feed