From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 562A23947419; Mon, 5 Dec 2022 18:30:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 562A23947419 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670265045; bh=aRzUvhQ92GB9SM8PDPySlCXyz/vyeBukCGIHBNTN/OM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=c1Zwt46i13xajkddrXDUfDO8KM/6o9rRPvis1XDCX6ubUxIIhz5RxJkQzO0h0P3fk EOFSPmYyM6I9Sd9BZobl0srmfSObLllIkyfwi/Y7xZ6T9g2Gql+KKsjW55f1dRuT+Q Qt7T7ft9bwq0EerBETi4F0ndIJkEo6jUW/n47ftM= From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105838] [10/11/12/13 Regression] g++ 12.1.0 runs out of memory or time when building const std::vector of std::strings Date: Mon, 05 Dec 2022 18:30:45 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: compile-time-hog, memory-hog X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105838 --- Comment #11 from Jakub Jelinek --- (In reply to Jason Merrill from comment #10) > A lot of the problem here is that building a std::string involves buildin= g a > std::allocator temporary to pass to the string constructor, and then > we need to wait until the entire array is built before we can destroy any= of > them: https://eel.is/c++draft/class.temporary#5 says we can only destroy > temporaries early if there was no initializer for that array element. So > for each element of the initializer we have another EH region for its > allocator temporary. >=20 > We could do better for the general case by creating a parallel array of > temporaries and using the same single cleanup region for it as for the ar= ray > of strings. This seems like a worthwhile general optimization. >=20 > We might be able to do better for the specific case by recognizing that > std::allocator has no data and nothing cares about its address, so we can= go > ahead and destroy it after initializing the string, and reuse the stack > slot. This also saves stack space. Even if we don't emit a loop (which I still think is the way to go for larg= er initializers because anything else means just too large code), can't there = for the larger initializers simply be some variable holding a counter how many initializers have been already initialized and a single EH region that will perform all the cleanups based on that counter?=