We added casts some time ago which allows us to change text_pool from int[] to void*[]. This makes it possible to store pointers in the text_pool, including pointers to other strings. Previously, to concatenate a string to a text, wrap_str needed to copy the whole string in the text_pool, taking time and more importantly memory.
Since almost all calls to wrap_str were with string literals which are constant, this copy operation is not necessary. This PR changes the type of text_pool to void*[] and adds wrap_str_const a function that can be used for constant strings (either literals or strings from the string pool which we know are constants).
Being avoiding many copies, about the peak text allocation is 25% lower and the cumulative text allocation is 30% lower.
For bootstrapping pnut.sh, this PR reduces the execution time by 1.5s for ksh, 3s for dash, 4s for bash. Other shells haven't been benchmarked but are likely also faster.
Context
We added casts some time ago which allows us to change
text_pool
fromint[]
tovoid*[]
. This makes it possible to store pointers in thetext_pool
, including pointers to other strings. Previously, to concatenate a string to atext
,wrap_str
needed to copy the whole string in thetext_pool
, taking time and more importantly memory.Since almost all calls to
wrap_str
were with string literals which are constant, this copy operation is not necessary. This PR changes the type oftext_pool
tovoid*[]
and addswrap_str_const
a function that can be used for constant strings (either literals or strings from the string pool which we know are constants).Being avoiding many copies, about the peak text allocation is 25% lower and the cumulative text allocation is 30% lower.
This PR:
Main:
For bootstrapping pnut.sh, this PR reduces the execution time by 1.5s for ksh, 3s for dash, 4s for bash. Other shells haven't been benchmarked but are likely also faster.