Details
-
Type:
Defect
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Completed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:
-
Patch:Code
Description
The first retraction of facts from a relation transforms the internal PersistentHashSet -set var+atom, which guarantees uniqueness, into a LazySeq which allows duplicate facts to be added. Once the first retraction occurs, a LazySeq persists for the rest of the life of the relation. Only the value of the primary -set var+atom is affected, not the -index var+atom values.
This issue is not an external correctness issue but does affect performance of subsequent duplicate fact additions which grow the size relation.
Preparation:
user=> (defrel foo x y)
#<user$eval4287$fn__4288 user$eval4287$fn__4288@1a9d489b>
user=> (facts foo [[:joe :man][:jane :woman][:sue :boy]])
nil
user=> foo_2-set
#<Atom@52aaf223: #{[:joe :man] [:jane :woman] [:sue :boy]}>
user=> (class @foo_2-set)
clojure.lang.PersistentHashSet
user=> (retraction foo :jane :woman)
nil
Without patch applied:
user=> foo_2-set #<Atom@52aaf223: ([:joe :man] [:sue :boy])> user=> (class @foo_2-set) clojure.lang.LazySeq user=> (facts foo [[:joe :man][:jane :woman][:sue :boy]]) nil user=> foo_2-set #<Atom@52aaf223: ([:sue :boy] [:jane :woman] [:joe :man] [:joe :man] [:sue :boy])> user=> (class @foo_2-set) clojure.lang.LazySeq
With patch applied:
user=> foo_2-set
#<Atom@31eb9b15: #{[:joe :man] [:sue :boy]}>
user=> (class @foo_2-set)
clojure.lang.PersistentHashSet
user=> (facts foo [[:joe :man][:jane :woman][:sue :boy]])
nil
user=> foo_2-set
#<Atom@31eb9b15: #{[:joe :man] [:jane :woman] [:sue :boy]}>
user=> (class @foo_2-set)
clojure.lang.PersistentHashSet
I've filed this as a Minor issue as it does not affect core.logic correctness and degraded performance can be avoided by not re-asserting duplicate facts.
I will also issue a GitHub pull request which can be used or ignored at your convenience.
Attachments
Activity
| Field | Original Value | New Value |
|---|---|---|
| Attachment | core.logic-rel-002.patch [ 11479 ] |
| Resolution | Completed [ 1 ] | |
| Status | Open [ 1 ] | Resolved [ 5 ] |