We're updating the issue view to help you get more done. 

Rel relation PersistentHashSet becomes LazySeq after issuing a retraction

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:

1 2 3 4 5 6 7 8 9 10 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:

1 2 3 4 5 6 7 8 9 10 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:

1 2 3 4 5 6 7 8 9 10 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.

Environment

None

Status

Assignee

David Nolen

Reporter

Aaron Brooks

Labels

Approval

None

Patch

Code

Priority

Minor