Permalink
Browse files

Optimize map-sum so we don't OOM when there are lots of options

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...
1 parent b19ae24 commit 5afeace2761eeb6731cf558bed354607e5401631 @gfredericks gfredericks committed with swannodette Jun 8, 2013
Showing with 5 additions and 3 deletions.
  1. +5 −3 src/main/clojure/clojure/core/logic/fd.clj
@@ -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]

0 comments on commit 5afeace

Please sign in to comment.