Skip to content

C++ GenerateText incurs a lot of overhead for outputs larger as 1024 bytes #6

@bvgastel

Description

@bvgastel

std::string is used as a accumulator for the output string in GenerateText(...) in idl_gen_text.cpp. Each time one byte is added, the entire string is copied in a new container. At least internally a better way of handling this is probably to use std::ostream &_text as argument for GenStruct (in idl_gen_text.cpp), and wrap in GenerateText the call to GenStruct with

std::stringstream stringaccumulator;
GenStruct(..., stringaccumulator);
_text = stringaccumulator.str();

Although text.reserve(1024); is a nice trick for micro benchmarks, this output method will incur unexpected large execution times for larger outputs.

Another benefit of using std::ostream as function signature is should be rather easy to change the output routine so accept calls like GenerateText(..., std::cout) (avoiding composing the entire buffer in memory).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions