[libcxx-commits] [PATCH] D65667: [libcxx] Avoid destructor call for error_category singletons
Louis Dionne via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Sep 1 08:27:17 PDT 2023
ldionne marked 3 inline comments as done.
ldionne added inline comments.
Herald added a subscriber: wangpc.
================
Comment at: libcxx/src/ios.cpp:62
+ _LIBCPP_NO_DESTROY constinit
+ static IostreamErrorHelper s;
+ return s.iostream_error_category;
----------------
hubert.reinterpretcast wrote:
> cebowleratibm wrote:
> > hubert.reinterpretcast wrote:
> > > ldionne wrote:
> > > > Actually, since those are `constinit`, I think we could even define them at file scope and skip the function-local static. Thoughts?
> > > That makes sense. It does have an advantage in cases where `_LIBCPP_NO_DESTROY` is not effective.
> > If `_LIBCPP_NO_DESTROY` is not effective, doesn't that mean that the user will pay the startup to register the atexit destruction, even if the category singleton is never used? I think the benefit of the static local remains: that you're not paying for it unless it's used. If `_LIBCPP_NO_DESTROY` is supported then there's no benefit to using static locals. Are we ok imposing the load time cost when the library is built without `_LIBCPP_NO_DESTROY` support?
> It's a trade-off between one-time startup cost versus dealing with the guard for every call.
Turns out there's no guard anyway since they are constinit.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D65667/new/
https://reviews.llvm.org/D65667
More information about the libcxx-commits
mailing list