[all-commits] [llvm/llvm-project] 1a5af3: [libc++] Speed up classic locale (take 2) (#73533)

Louis Dionne via All-commits all-commits at lists.llvm.org
Wed Nov 29 06:31:20 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1a5af34e6fcb56098e67d3272e1e89a05528f15e
      https://github.com/llvm/llvm-project/commit/1a5af34e6fcb56098e67d3272e1e89a05528f15e
  Author: Louis Dionne <ldionne.2 at gmail.com>
  Date:   2023-11-29 (Wed, 29 Nov 2023)

  Changed paths:
    M libcxx/benchmarks/stringstream.bench.cpp
    M libcxx/include/CMakeLists.txt
    M libcxx/include/__locale
    A libcxx/include/__utility/no_destroy.h
    M libcxx/include/module.modulemap.in
    M libcxx/src/locale.cpp

  Log Message:
  -----------
  [libc++] Speed up classic locale (take 2) (#73533)

Locale objects use atomic reference counting, which may be very
expensive in parallel applications. The classic locale is used by
default by all streams and can be very contended. But it's never
destroyed, so the reference counting is also completely pointless on the
classic locale. Currently ~70% of time in the parallel stringstream
benchmarks is spent in locale ctor/dtor. And the execution radically
slows down with more threads.

Avoid reference counting on the classic locale. With this change
parallel benchmarks start to scale with threads.

This is a re-application of f8afc53d641c (aka PR #72112) which was
reverted in 4e0c48b907f1 because it broke the sanitizer builds due
to an initialization order fiasco. This issue has now been fixed by
ensuring that the locale is constinit'ed.

Co-authored-by: Dmitry Vyukov <dvyukov at google.com>




More information about the All-commits mailing list