in_systemd: improve performance when packaging fields
in_systemd: improve performance when packaging fields

When processing records, each one have multiple fields and due to
serialization when converting from Systemd format to Fluent Bit, we
need to know beforehand how many fields a record contains before
do the packaging. Systemd C API do not expose a function to get the
number of fields contained in a record, so the solution was to iterate
all fields and do the proper counting. This procedure is not optimal
for performance since once the fields are counted, we need to iterate
all fields again to do the packaging.

I've opened a RFE with Systemd team asking for such missing feature:

  https://github.com/systemd/systemd/issues/10906

In the meanwhile, this patch workaround the problem in the following way:

  - Pack (register) the maximum number of fields allowed by 'max_fields'
    property.
  - Iterate, count and package all Systemd fields from the record.
  - Do a manual adjustment of the msgpack Map size header.

With this approach there is a performance improvement:

  - before => in_systemd_collect():  78.39%
  - after  => in_systemd_collect():  73.90%

this improvement represents a ~4.5% gain in performance.

note: the test was done using Valgrind (--tool=callgrind) processing 4k of
records coming from the Journal.

Signed-off-by: Eduardo Silva <81f705dc2ce1a61a2621e0e4b442a9474e1d0c70@treasure-data.com>

fluent/fluent-bit,nokute78/fluent-bit,nokute78/fluent-bit,fluent/fluent-bit,nokute78/fluent-bit,nokute78/fluent-bit,fluent/fluent-bit,nokute78/fluent-bit,nokute78/fluent-bit,fluent/fluent-bit,fluent/fluent-bit,fluent/fluent-bit,fluent/fluent-bit,nokute78/fluent-bit,nokute78/fluent-bit,fluent/fluent-bit,fluent/fluent-bit,nokute78/fluent-bit,fluent/fluent-bit,nokute78/fluent-bit,nokute78/fluent-bit,nokute78/fluent-bit,fluent/fluent-bit,fluent/fluent-bit