Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Potential performance regression of vformat_to in libfmt 11 compared to libfmt 10.2.1 #4070

@odygrd

Description

@odygrd

Hello,

I am experiencing a drop in throughput when migrating my logging library to libfmt 11 compared to libfmt 10.2.1.

I haven't been able to figure out yet if this is something related to my project or the newer version of libfmt, but the only change is the libfmt library.

Environment
Compiler: GCC 13
OS: Linux RHEL
Build Configuration: Release build with -O3 -DNDEBUG -std=gnu++20
libfmt: Header-only version

#include "quill/bundled/fmt/base.h"
#include "quill/bundled/fmt/format.h"

#include <string>
#include <iostream>
#include <chrono>
#include <atomic>

void ClobberMemory() {
  std::atomic_signal_fence(std::memory_order_acq_rel);
}

int main()
{
  using format_buffer_t = fmt::basic_memory_buffer<char>;

  fmt::string_view format_str = "Hello, {}. The answer is {} and {}.";

  int a = 1;
  int b = 2345;
  int c = 6789;
  auto args = fmt::make_format_args(a, b, c);

  const int n = 10'000'000;

  auto start = std::chrono::high_resolution_clock::now();

  for (int iteration = 0; iteration < n; ++iteration)
  {
    format_buffer_t buffer;
    fmt::vformat_to(std::back_inserter(buffer), format_str, args);
  }

  ClobberMemory();

  auto end = std::chrono::high_resolution_clock::now();

  std::chrono::duration<double> duration = end - start;
  double total_time = duration.count() * 1000;  // Convert to milliseconds

  std::cout << "Total time for formatting " << n << " strings: "
            << total_time << " ms" << std::endl;

  return 0;
}

I ran the above several times for both versions and it seems that version 10.2.1 is always faster. I am running it on an isolated cpu and nothing else is running on the whole box

image

Are there any known changes in libfmt 11 that could explain this difference?

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