From: Jonathan Wakely <jwakely@redhat.com>
To: Vittorio Romeo <mail@vittorioromeo.com>
Cc: "libstdc++" <libstdc++@gcc.gnu.org>
Subject: Re: First-time contributor -- speeding up `std::unique_ptr` compilation
Date: Mon, 25 Jul 2022 22:34:10 +0100 [thread overview]
Message-ID: <CACb0b4n7ttLPOxtNHigj32rG0hPcy+ZK1z6cin_MHfSakAuc+g@mail.gmail.com> (raw)
In-Reply-To: <DU0P189MB2067A922CA5EADC7303FD412E1B79@DU0P189MB2067.EURP189.PROD.OUTLOOK.COM>
[-- Attachment #1: Type: text/plain, Size: 565 bytes --]
On Sat, 25 Jun 2022 at 13:45, Vittorio Romeo wrote:
>
> Thank you, Jonathan, for the very thorough explanation and for pointing out that I completely forgot to consider ABI stability in this case.
>
> I still think that it might be worthwhile to attempt some work in this area as multiple projects I work on have various TUs using unique_ptr but not tuple. I will look into the refactoring you suggested.
Something like this would avoid instantiating most of std::tuple while
preserving ABI, but it doesn't seem to really make much difference to
compilation time.
[-- Attachment #2: unique_ptr.patch --]
[-- Type: text/x-patch, Size: 2388 bytes --]
diff --git a/libstdc++-v3/include/bits/unique_ptr.h b/libstdc++-v3/include/bits/unique_ptr.h
index e1ad7721a59..777c7dec15a 100644
--- a/libstdc++-v3/include/bits/unique_ptr.h
+++ b/libstdc++-v3/include/bits/unique_ptr.h
@@ -172,7 +172,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__uniq_ptr_impl() = default;
_GLIBCXX23_CONSTEXPR
- __uniq_ptr_impl(pointer __p) : _M_t() { _M_ptr() = __p; }
+ __uniq_ptr_impl(pointer __p) : _M_t(__p) { }
template<typename _Del>
_GLIBCXX23_CONSTEXPR
@@ -193,13 +193,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
_GLIBCXX23_CONSTEXPR
- pointer& _M_ptr() noexcept { return std::get<0>(_M_t); }
+ pointer& _M_ptr() noexcept { return _M_t._M_ptr(); }
_GLIBCXX23_CONSTEXPR
- pointer _M_ptr() const noexcept { return std::get<0>(_M_t); }
+ pointer _M_ptr() const noexcept { return _M_t._M_ptr(); }
_GLIBCXX23_CONSTEXPR
- _Dp& _M_deleter() noexcept { return std::get<1>(_M_t); }
+ _Dp& _M_deleter() noexcept { return _M_t._M_deleter(); }
_GLIBCXX23_CONSTEXPR
- const _Dp& _M_deleter() const noexcept { return std::get<1>(_M_t); }
+ const _Dp& _M_deleter() const noexcept { return _M_t._M_deleter(); }
_GLIBCXX23_CONSTEXPR
void reset(pointer __p) noexcept
@@ -226,9 +226,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
swap(this->_M_ptr(), __rhs._M_ptr());
swap(this->_M_deleter(), __rhs._M_deleter());
}
-
private:
- tuple<pointer, _Dp> _M_t;
+ struct _Tuple : _Head_base<1, _Dp>, _Head_base<0, pointer>
+ {
+ using _Ptr_base = _Head_base<0, pointer>;
+ using _Del_base = _Head_base<1, _Dp>;
+
+ _Tuple() = default;
+ _Tuple(_Tuple&&) = default;
+
+ constexpr
+ _Tuple(pointer __p) : _Ptr_base(__p) { }
+
+ template<typename _Del>
+ constexpr
+ _Tuple(pointer __p, _Del&& __d)
+ : _Del_base(std::forward<_Del>(__d)), _Ptr_base(__p)
+ { }
+
+ constexpr pointer&
+ _M_ptr() noexcept { return _Ptr_base::_M_head(*this); }
+ constexpr pointer
+ _M_ptr() const noexcept { return _Ptr_base::_M_head(*this); }
+ constexpr _Dp&
+ _M_deleter() noexcept { return _Del_base::_M_head(*this); }
+ constexpr const _Dp&
+ _M_deleter() const noexcept { return _Del_base::_M_head(*this); }
+ };
+
+ _Tuple _M_t;
};
// Defines move construction + assignment as either defaulted or deleted.
prev parent reply other threads:[~2022-07-25 21:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-24 0:19 mail
2022-06-24 6:20 ` Jonathan Wakely
2022-06-24 7:22 ` Jonathan Wakely
2022-06-25 12:45 ` Vittorio Romeo
2022-07-25 21:34 ` Jonathan Wakely [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CACb0b4n7ttLPOxtNHigj32rG0hPcy+ZK1z6cin_MHfSakAuc+g@mail.gmail.com \
--to=jwakely@redhat.com \
--cc=libstdc++@gcc.gnu.org \
--cc=mail@vittorioromeo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).