Skip to content

Commit

Permalink
Optimize map-sum so we don't OOM when there are lots of options
Browse files Browse the repository at this point in the history
Using conde for domains on lots of logic vars can result in
exponential memory usage due to conde's interleaving (which is itself
caused by conde wrapping its result in -inc). This commit changes
map-sum such that it should be equivalent to the old version without
the -inc. This should be a valid change since the unification goals
should not diverge.
  • Loading branch information
gfredericks authored and swannodette committed Jun 9, 2013
1 parent b19ae24 commit 5afeace
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/clojure/clojure/core/logic/fd.clj
Expand Up @@ -656,9 +656,11 @@
(fn loop [ls]
(if (empty? ls)
(fn [a] nil)
(conde
[(f (first ls))]
[(loop (rest ls))]))))
(fn [a]
(mplus
((f (first ls)) a)
(fn []
((loop (rest ls)) a)))))))

(defn to-vals [dom]
(letfn [(to-vals* [is]
Expand Down

0 comments on commit 5afeace

Please sign in to comment.