public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Patrick Palka <ppalka@redhat.com>
To: Patrick Palka <ppalka@redhat.com>
Cc: gcc-patches@gcc.gnu.org, jason@redhat.com
Subject: Re: [PATCH] c++: Improve memory usage of subsumption [PR100828]
Date: Mon, 19 Jul 2021 18:13:40 -0400 (EDT)	[thread overview]
Message-ID: <6174cc5-4259-c954-41c8-9217c71e335@idea> (raw)
In-Reply-To: <20210719220529.2446563-1-ppalka@redhat.com>

On Mon, 19 Jul 2021, Patrick Palka wrote:

> Constraint subsumption is implemented in two steps.  The first step
> computes the disjunctive (or conjunctive) normal form of one of the
> constraints, and the second step verifies that each clause in the
> decomposed form implies the other constraint.   Performing these two
> steps separately is problematic because in the first step the
> disjunctive normal form can be exponentially larger than the original
> constraint, and by computing it ahead of time we'd have to keep all of
> it in memory.
> 
> This patch fixes this exponential blowup in memory usage by interleaving
> these two steps, so that as soon as we decompose one clause we check
> implication for it.  In turn, memory usage during subsumption is now
> worst case linear in the size of the constraints rather than
> exponential, and so we can safely remove the hard limit of 16 clauses
> without introducing runaway memory usage on some inputs.  (Note the
> _time_ complexity of subsumption is still exponential in the worst case.)
> 
> In order for this to work we need formula::branch to prepend the copy
> of the current clause directly after the current clause rather than
> at the end of the list, so that we fully decompose a clause shortly
> after creating it.  Otherwise we'd end up accumulating exponentially
> many (partially decomposed) clauses in memory anyway.
> 
> Bootstrapped and regtested on x86_64-pc-linux-gnu, and also tested on
> range-v3 and cmcstl2.  Does this look OK for trunk and perhaps 11?

Here's a testcase that demonstrates the exponential improvement, because
the DNF/CNF for the below constraints has around 2^23 clauses.  Before
this patch (but after removing the hard limit of 16 clauses), compile
time and memory usage is 7s/2.4GB.  After this patch, it's 3.5s/25MB.

-- >8 --

template<class T> concept C = true;

template<class T>
requires (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
  || (C<T> && C<T>)
struct k;

template<class T>
requires (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && (C<T> || C<T>)
  && true
struct k<T> { };


  reply	other threads:[~2021-07-19 22:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-19 22:05 Patrick Palka
2021-07-19 22:13 ` Patrick Palka [this message]
2021-07-28 20:42 ` Jason Merrill
2021-08-09 21:07   ` Patrick Palka
2021-08-11 13:46     ` Jason Merrill
2021-08-11 14:53       ` Patrick Palka
2021-08-11 17:41         ` Jason Merrill

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=6174cc5-4259-c954-41c8-9217c71e335@idea \
    --to=ppalka@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.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).