Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 386: Remove unneeded memory operations from ProductionNode #387

Merged
merged 6 commits into from
Apr 3, 2018

Conversation

WilliamParker
Copy link
Collaborator

This is an incomplete draft but demonstrates the design of the changes.

TODOs:

  • Potentially rename new functions, keywords, etc. I didn't put much thought into the names at this stage.
  • Write more docstrings and code comments as appropriate.
  • Fix the tracing tests.
  • Optional (could be a later PR): Add additional session inspection keys using the new listener e.g. explanations of unconditionally inserted facts and/or retractions.

@@ -337,17 +337,17 @@
ILeftActivate
(left-activate [node join-bindings tokens memory transport listener]

;; Provide listeners information on all left-retract calls for passivity,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor thing, but I think it is more important than just preserving old behavior. I think it is really useful behavior to be able to listen for this activity in the ProductionNode still.

@@ -1766,6 +1767,11 @@
;; Therefore, the reordering of retractions and insertions should have no impact
;; assuming that the evaluation of rule conditions is pure, which is a general expectation
;; of the rules engine.
(l/fire-activation! listener
activation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These extra deref calls are going to incur runtime cost. That's sort of an unfortunate part of the listener calls in the engine all being functions (as opposed to macros that could try to mitigate the cost when they are "off").

In this case, I think You could just bind to the derefed values here and use them in the places you need them. They are needed outside of the l/fire-activation! call anyways.

(defn remove-listeners
[session pred]
(let [{:keys [listeners] :as components} (components session)
matching-listeners (filterv pred listeners)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using some here would make more sense. No reason to build a vector of all the matches that aren't used later.

(if (seq matching-listeners)
(assemble (assoc components
:listeners
(remove pred listeners)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like something that'd be better off not lazy. It just seems questionable when it will be realized later.
(into [] (remove pred) listeners)

(deftype TransientRuleActivationListener [activations]
l/ITransientEventListener
(fire-activation! [listener activation resulting-operations]
(reset! (.-activations listener) (conj @(.-activations listener) {:activation activation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a slower version of swap! I believe

(swap! (.-activations listener) conj {:activation activation :resulting-operations resulting-operations})

(fire-rules! [listener node]
listener))

(deftype PersistentRuleActivationListener [activations]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if "rule" is needed in these names. Could it all just be "activation listener" instead of "rule activation listener"?

(remove pred listeners)))
session)))

(defn listeners-matching-pred
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhapsfind-listeners?

@WilliamParker
Copy link
Collaborator Author

I've pushed some more commits up that address previous comments and generally clean this up. I'll want to go over it once more before merging but my objective was to clean it up to a mergeable state. I think we can delay adding more keys to session inspection to a future PR.

@rbrush
Copy link
Contributor

rbrush commented Mar 29, 2018

+1 to this change. (And thanks to Will for giving me a heads up here.)

@WilliamParker WilliamParker merged commit 7aedaa5 into oracle-samples:master Apr 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants