From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075070.outbound.protection.outlook.com [40.92.75.70]) by sourceware.org (Postfix) with ESMTPS id 7B428385AE44 for ; Sat, 25 Jun 2022 12:45:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7B428385AE44 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vittorioromeo.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=outlook.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bciBrK0SoA6gbsIMe50XnJk4sqfHCKd5ygAFp+iBVW9sW1t7VAv6Da+MkaO99QL+5oOU0wSC8RYXZcJkk+H2yeK5CzOVPqU7uNRh6x4CCmdETpnRpKv4MUQX/PQpgHi42Tk4GlUfMWjqzXLbHZVe0dTmbWAslcTEv5ce/Z7jNGD06M6YPHoxKwEH/PQ90U8pxzgB7RzRWT1hj0viY2kbb2miIpTYqvFxTqRb516SfcnlSe9sf0ge0C7VSIxXvGizXZJHHX3GpNTTn96bugTJ7F1/GANrTQ5aewjZouj1CglFJqHGE6szgI8V+BRVoPvRpMajdg0hHAG7dgUOCiwPfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GcoVBCYrxid0A7HbO05UJkq3E/BYg/1G8Qp1q84VVW4=; b=loI+NP9VYv9KJu7AoG6sNGCCAMLtspxPHD44NXc4KS72IhHiStT+lJk0SqPcENDUfoP6OzlaKheRT6wNRAkQDEPdEFa1iP8mIUyiuIYzsxwdrJS2VwW2m8HnadF3wgbMK3m7zPvTWv8w9uPk2lcYQr4rSWnv1Ig4iFcX5G0RlP+AMO7tG/+y7/VjN7ABAKvviNqQj/4MSueBDyk973vfIyS9KEKqFMWcPxgQm1d3o8zkwazR+aJk8ZjoXlJy+bPlbkGtSZwZevHhejkPOwnBOKRmB9qR3lSP2reJA30nWW8iyg6KksnkBAYfN+ctqth6vjLeTIzfepfvHTdkniGpQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GcoVBCYrxid0A7HbO05UJkq3E/BYg/1G8Qp1q84VVW4=; b=MYpTPGFz1AmUQauldma36ep4QwW5XQZMQ8y989XTwX0g4ErNSw2jXmJTTrzOCP+ZuQTjaAX2tlrx+k/PW61i91b/98jfg8yca4KLj021snWfG/txFbo9+yqQqKWMT8UwZHJR3ZX2m9fNpmuWTyIJjVZTI2en+RihJKYNsxg9MIF3nJEkyKmzlF8vgPYBxLTN11A/0ueyuPIsflsQNn3ifUlYrQNxiRr2Xd4iBV2jUTQYSzfq23n7tykIrYqSg/xS5jmCc/1K6Ws2Hi7Ncg27aPYhG8IitUThifzI066/CDBbvi40L5f0Iux1GCdC93IgIfHKmyWR3KWRvM0JYXKFMQ== Received: from DU0P189MB2067.EURP189.PROD.OUTLOOK.COM (2603:10a6:10:3bc::15) by AM7P189MB0664.EURP189.PROD.OUTLOOK.COM (2603:10a6:20b:119::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5373.16; Sat, 25 Jun 2022 12:45:36 +0000 Received: from DU0P189MB2067.EURP189.PROD.OUTLOOK.COM ([fe80::ac5e:d2c1:dba4:32b]) by DU0P189MB2067.EURP189.PROD.OUTLOOK.COM ([fe80::ac5e:d2c1:dba4:32b%6]) with mapi id 15.20.5373.016; Sat, 25 Jun 2022 12:45:30 +0000 From: Vittorio Romeo To: Jonathan Wakely CC: libstdc++ Subject: Re: First-time contributor -- speeding up `std::unique_ptr` compilation Thread-Topic: First-time contributor -- speeding up `std::unique_ptr` compilation Thread-Index: AQHYh16sh+QBgQe+70mrZW6kBqWUja1eFkKAgAARcwCAAev1Ag== Sender: Vittorio Romeo Date: Sat, 25 Jun 2022 12:45:30 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 2 x-tmn: [d7DxkIo6NccXfdyFUUXEYLtWWo/Qp20RmPhcl/5NaKk=] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 206be03e-ad94-4cd3-6667-08da56a89697 x-ms-traffictypediagnostic: AM7P189MB0664:EE_ x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: EEpfYnqbzmSX5akMmoi6n4FjD+fXrCKWUctrO+jwLeYge/pVmI9cQFhts07G+0Bp/3KyTrr5wjiVc+hvvbTBBdcwBE675VEksrK6M2n+dtv/HVXaGS3r5VTndfT+/rMe1SvNYvEKQFYqnacZVkmYiLQ7RKnV+7+IJbWOeQ3dXcGgKNzjZ6uuwg6oGzFzZiNR1/DcCS3NLiwXxTUMNjRX/iSMonWLuYy/igErL9MOE1ii2AJ0bdQoycAbTfEEY+YJkw7wbt4xD7z6aB6j6EqY3XUMNbOdjmfGGJHOGi2t3Km1hAtrVmjS9Nun586UmNKhRE5ezM6Ku9o8tAvUWZ0XInjvmr6ki59wvL3VjyE9XWeBo3sbvEgm6aMJ/PXqrGKZh4EYoLQg6mlricdi5Q9bGZtRxMiJZb2wunq0zCxoSEE/q9YOBzFd14C8m+0AJiLtL1DnbxSFhWit4y70HfureRAv71f54F8SX3fEt8KxXtqT5/nTm5CA3xEQvbYERfm6AeNdNbApLGJWDZV8pA06LRYZXVJofJ+xMiYCNsoQJ4cwa6OejSmNaiRBZCkoNsRhNBB0iXs4qI2DopVPO9FVTnOL3y0OcNfqYwGTic0sKX1PNpqms/IwjE21C/Zns15f x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?m+g4dmd1WoPmrkKRvAlolKqTo+Ir0GFI4X85lqI34D6hqWXWC2TeD3nTmA8Q?= =?us-ascii?Q?8/PhprUDAekJLt3MSioOESgix28Isz2lCq7E8mkouGds5p5vldvdINNb2Ybn?= =?us-ascii?Q?i8qjOIQi97FHVPOtpU5lvAu9+MfGMfDGPnLID4gciwUjjSHJHuc4jbdDJ8iT?= =?us-ascii?Q?GprVdJsSLQz7NTYSS70I6HMHekRuiYI5VqWsO96TtzGk5W6Ugvq85DsVXmjD?= =?us-ascii?Q?5mjIVJMNLcVCbVlRBmqjGQPnIgdKeZUOApwmx8jVF8TGZcynbIZ/XLtR1rsG?= =?us-ascii?Q?jbe/6bSot52ezmaqkqQ2obb+fTxgF8v7fvIrZXRhqgwfYBT1+UfIh7cyZIA3?= =?us-ascii?Q?2Q9DGVIlAyxmEVCoi2h/BvtHq5SY+vmwpDQ2kymQ91uhtvJtSq2bfi2iL4Nd?= =?us-ascii?Q?oj/q05uxdcjz3gdn4UfbSc4ZsvD/Y5fS+bLcTf6ixu4d0rpbt4z0ovW24FuJ?= =?us-ascii?Q?/ns7zQ9A5bOlqQNZs3sTjD+hB1BxMiRznttk/9RNtgNIIqw9i3dPNlMvUX6M?= =?us-ascii?Q?jAmOszQYD2IqKFEPcYtEC51kyRh4Q3CSH9yFQTUKavDfl4l1ePQP65AUW1Se?= =?us-ascii?Q?e0ZhwRqQTGsYF1uqPt95zdlM01397sHfNE6IEYtoEC6LZ817P2xJNWtDuFaD?= =?us-ascii?Q?/rnioH8Oo8lOtIAtTdVpcsNZqqExuR18r3G+6oAf0ImxRTwVdY62aJUXQpRA?= =?us-ascii?Q?E2s/Zmx3iG6gWfRSJLIBufka1e8cMnGs1pswkgLZZN+bf6LbEMQtgPSH3K4A?= =?us-ascii?Q?XDOVcbhxiIINdbjtjzVgLhfOR2iKMz7CIfvr9rqc+HFUG4kIW0xYhI4CXERI?= =?us-ascii?Q?W3XFVuPy8FMaHdroWOuetUvCMVCGavWVEQXmbXmrhn2BT3o6hTBUa4o9SkD+?= =?us-ascii?Q?A4VECWgObCL2ktSh2sybeN3HaWD9tGAebG0X7EPFLJYd3DWoFeMwTOYjdGyn?= =?us-ascii?Q?qQ01JdDVLTXm7dr6FjHvupIr9kJMaINL5qXRr6ZbmZKMz2/HJu8dg9LusT9I?= =?us-ascii?Q?EXGTbY2LdjGMYwRi86B98GDXwlbHZkddkHVf7d+2NpDAAkWsrKt2xUCW00W4?= =?us-ascii?Q?Y7ytGgtMEig6WTE1xJaNousxhgfkrdIGeHyP8nFa3shYcgdW4foYX1c7NIGG?= =?us-ascii?Q?bhmlXBlbUyurC23qX7f1snNaU5Zc20LlaYpjuT25b2kwEDD2oQKUsmdSzsdF?= =?us-ascii?Q?GU0tHByCY24sXuZ0gNqVk11XvlZpRp/4PZMgP8FDx6ik4en5KVPXmGRLMIbk?= =?us-ascii?Q?M4reMFjfZ/MXHswzTz6SRFea4AwGzz+IXY0VmN7BdXRunRk9jI/wYK+FE5n8?= =?us-ascii?Q?UZUtZnDjrapmQ62o/Lf1QX2Ypoom+Tvt8U+Zj52uNIf/SQ=3D=3D?= MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DU0P189MB2067.EURP189.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 206be03e-ad94-4cd3-6667-08da56a89697 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Jun 2022 12:45:30.6720 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7P189MB0664 X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE, KAM_INFOUSMEBIZ, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Jun 2022 12:45:41 -0000 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 t= uple. I will look into the refactoring you suggested. Vittorio Romeo https://vittorioromeo.info ________________________________ From: Jonathan Wakely Sent: Friday, June 24, 2022 9:22:56 AM To: mail@vittorioromeo.com Cc: libstdc++ Subject: Re: First-time contributor -- speeding up `std::unique_ptr` compil= ation On Fri, 24 Jun 2022, 07:20 Jonathan Wakely, > wrote: On Fri, 24 Jun 2022, 01:19 , > wrote: Hello everyone, Hope you are all doing well. I would like to begin by saying that I am terribly unfamiliar with mailing = lists and I've always found them cumbersome to use -- I tend to do most of = my development via GitHub PRs and Discord. Therefore, please forgive me if = this is not the right place to discuss "how to contribute", and also forgiv= e me for not being able to create a proper patch file. My goal is to generally improve the compilation speed of C++ programs using= the standard library. In personal projects and open-source projects I main= tain, I've achieved good results by benchmarking compilation via ClangBuild= Analyzer, figuring out the bottlenecks, and optimizing them. While working = on the SFML project, I noticed that the `std::unique_ptr` template was taki= ng a lot of time to be instantiated using the latest version of libstdc++. I investigated a bit, and figured out that the `` include and `std::= tuple` instantiation were the culprit. I then replaced them with a handmade= workaround in my system libraries, recompiled SFML, and noticed that `std:= :unique_ptr`'s instantiation time became negligible as a result of my chang= es. As a side benefit, we also avoid including the '' header altoget= her, reducing the risk of unintended transitive includes. I created a PR on= the GCC GitHub mirror as a way to observe the diff in a nice interface and= to discuss my changes, and to see if the maintainers generally think that = this is a good idea. You can see the diff here: https://github.com/gcc-mirror/gcc/pull/67/files?diff=3Dsplit&w=3D1 In terms of rough measurements, the average instantiation time of `std::uni= que_ptr` went from 22ms to 4ms. This was measured over the entire SFML code= base using clang++ 14.x with the `-ftime-trace` flag, plus the aforemention= ed ClangBuildAnalyzer tool. A few questions: 1. Is this improvement something that the libstdc++ maintainers would wa= nt to merge in? Of course, the changes need to be cleaned up and adapted to= GCC's coding style. No, it would be a ABI break. It would change the layout for a deleter with = the 'final' specifier. It also looks like quite a maintenance headache "just" for improved compila= tion time. The need for two implementations (with and without the attribute= ) that both need to be kept ABI compatible with std::tuple doesn't seem lik= e a good trade off and a good use of maintainer effort. I think a more maintainable (and ABI compatible) approach would be to move = the _Head_base templates to a new header and include that in bits/unique_pt= r.h, without the rest of . That will also allow the gdb pretty print= ers to continue working, whereas your suggestion would mean rewriting them. I know you are concerned about build times, but correctness, ABI compatibil= ity, and to a lesser extent maintainability all matter more. Build times fo= r microbenchmarks can be worth checking, but bear in mind that your changes= actually mean *more* code needs to be compiled for a program that already = uses std::tuple anyway. You're not removing any code from the library or ma= king the existing tuple code faster to compile, only adding more code. 2. If so, what is the easiest way to create a patch in the format that y= ou are used to and test it against libstdc++'s test suite? I have never con= tributed to libstdc++ or GCC before. You need to test it first, before you create a patch. Build your modified s= ources as per https://gcc.gnu.org/wiki/InstallingGCC (but starting with you= r git clone instead of a release tarball). You can use --enable-languages=3Dc++ to avoid building more of the compiler= then you need for libstdc++ testing. In the libstdc++ build directory (e.g. x86_64-pc-linux-gnu/libstdc++-v3) ru= n make check to run the tests, adding -j8 or a suitable option for your num= ber of cores. See https://gcc.gnu.org/onlinedocs/libstdc++/manual/test.html#test.run for = testing docs. Once you're happy with the results see https://gcc.gnu.org/contribute.html = for patch submission.