Unlike ConcreteEntry, MutableEntry can be appended to. Reserving the
exact number of elements before every append is harmful: vector will
likely reallocate each time and grow linearly instead of geometrically.
This results in quadratic behaviour when we spill past the preallocated
capacity and doesn't benefit the fast path in any way.
The new test case takes half a second with this patch and many hours
spinning in memmove without this patch.
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
void push(std::string_view sv)
{
- vec.reserve(vec.size() + sv.size());
vec.insert(vec.end(), sv.begin(), sv.end());
}
log.stop();
}
+TEST(Log, LargeFromSmallLog)
+{
+ SubsystemMap subs;
+ subs.set_log_level(1, 20);
+ subs.set_gather_level(1, 10);
+ Log log(&subs);
+ log.start();
+ log.set_log_file("/tmp/big");
+ log.reopen_log_file();
+ int l = 10;
+ {
+ MutableEntry e(l, 1);
+ for (int i = 0; i < 1000000; i++) {
+ std::string msg(10, 'a');
+ e.get_ostream() << msg;
+ }
+ log.submit_entry(std::move(e));
+ }
+ log.flush();
+ log.stop();
+}
+
// Make sure nothing bad happens when we switch
TEST(Log, TimeSwitch)