This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gold][patch] Reduce heap usage for string merge sections


>> + ?// Count the number of strings in the section and size the list.
>> + ?size_t count = 0;
>> + ?for (const Char_type* pl = p; pl < pend; ++pl)
>> + ? ?{
>> + ? ? ?if (*pl == 0)
>> + ? ? ++count;
>> + ? ?}
>
> In the case where Char_type is char, I have a feeling this loop would be
> a tiny bit faster if written as
>
> ?const Char_type* pl = p;
> ?while (pl < pend)
> ? ?{
> ? ? ?pl += strlen(pl) + 1;
> ? ? ?if (pl > pend)
> ? ? ? ?warning(...);
> ? ? ?++count;
> ? ?}
>
> This is simply because the compiler will optimize strlen for the
> specific compilation target. ?See
> Stringpool_template<char>::string_length for a similar optimization in
> the Stringpool code.

Good idea -- that got a little over 1% speedup (measured with -O2). I
pulled the string_length template and its char specialization out of
the Stringpool_template class, and used that in both the counting and
the add-to-pool loops, after checking for string sections that don't
end in a null.

> Also, since you have the exact count, it would be a tiny bit better to
> allocate the vector at that size rather than allocating a default vector
> and then using reserve. ?You could this by adding a parameter to the
> Merged_strings_list constructor which is passed to merged_strings.

That turned out to hurt performance a bit (maybe -- the difference was
close to the noise), probably because of the default constructor for
each allocated element. I left this part as is.

Here's the patch as committed.

-cary


        * merge.cc (Output_merge_string::do_add_input_section): Count strings
        to reserve space in merged_strings vector. Keep total input size
        for stats.
        (Output_merge_string::do_print_merge_stats): Print total input size.
        * merge.h (Output_merge_string): Add input_size_ field.
        * stringpool.cc (Stringpool_template::string_length): Move
        implementations out of Stringpool_template class and place in
        stringpool.h.
        * stringpool.h (string_length): Move out of Stringpool_template.

Attachment: gold-merge-count-patch-2.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]