zeek/spicy

std::string parameters for debug::indent() and debug::dedent() in generated code

Closed this issue · 1 comments

Separate follow up to #1589 . Looking at the generate code for the following grammar:

type K = unit {
  x: skip bytes &size=1;
};

type L = unit {
  k: K;
};

type M = unit {
  l: L;
};

public type N = unit {
  : M[] &eod;
};

There's a number of indent() and dedent() calls generated involving std::string instances being constructed at runtime. These are pretty short strings so they shouldn't involve an allocation and might be optimized well, but might still be sensible to not even construct them.

    try {
        ::hilti::rt::debug::indent(std::string("spicy"));
        std::optional<::hilti::rt::stream::SafeConstIterator> __begin = std::make_optional(__cur.begin());


    ::hilti::rt::debug::dedent(std::string("spicy"));

A flamegraph indicates ~3.3% samples falling into basic_string functions.

flame

Screenshot-20231110-120557

Unfortunately I don't have the means to provide before-after here.

Unfortunately I don't have the means to provide before-after here.

I used the approach from #1593 and #1592 simply commenting out the debug::dedent and debug::indent calls in the generated code and then re-building. Removes ~10% of runtime for that particular reproducer.