Skip to content

Commit

Permalink
v0.1.2
Browse files Browse the repository at this point in the history
* Removed uneeded calls to `.then` to address performance degredation (#30)
  • Loading branch information
doug-martin committed May 24, 2013
1 parent ac9fe0d commit 8aa530a
Show file tree
Hide file tree
Showing 10 changed files with 2,057 additions and 1,979 deletions.
47 changes: 47 additions & 0 deletions benchmark/simple/benchmark.js
@@ -0,0 +1,47 @@
"use strict";
var nools = require("../../"),
defined = {},
constraints = [],
COUNT = 5;

for (var i = 0; i < COUNT; i++) {
constraints.push([defined["Object" + i] = function (value) {
this.name = value;
}, "m" + i]);
}


var start = new Date().getTime();

var execCount = 0;

var flow = nools.flow("Performance Test", function () {

//find any message that starts with hello
this.rule("Rule1", constraints, function () {

execCount++;
console.log("execCount: " + execCount);
}
);

});

var session = flow.getSession();

for (var j = 0; j < COUNT; j++) {
for (var k = 0; k < COUNT; k++) {
session.assert(new defined["Object" + k](j + " " + k));
}
}

session.match(function (err) {
if (err) {
throw err;
}
var end = new Date().getTime();
var diff = end - start;
console.log("elapsed: " + diff);
});


6 changes: 5 additions & 1 deletion docs/History.html
Expand Up @@ -176,7 +176,11 @@



<p>v0.1.1</p>
<h1>v0.1.2 / 2012-05-24</h1>
<ul>
<li>Removed unneeded calls to <code>.then</code> to address performance degredation (#30)</li>
</ul>
<h1>v0.1.1 / 2012-05-23</h1>
<ul>
<li>Updated grunt</li>
<li>Fixed nextTick issues for node v0.10 #32</li>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Expand Up @@ -183,7 +183,7 @@ <h1>Nools</h1>
<p>Nools is a <a href="http://en.wikipedia.org/wiki/Rete_algorithm">rete</a> based rules engine written entirely in javascript.</p>
<h1>Installation</h1>
<pre class='prettyprint linenums lang-js'><code>npm install nools</code></pre>
<p>Or <a href="https://raw.github.com/doug-martin/C2FO/master/nools.js">download the source</a> (<a href="https://raw.github.com/doug-martin/C2FO/master/nools.min.js">minified</a>)</p>
<p>Or <a href="https://raw.github.com/C2FO/nools/master/nools.js">download the source</a> (<a href="https://raw.github.com/C2FO/nools/master/nools.min.js">minified</a>)</p>
<h1>Usage</h1>
<ul>
<li>Flows<ul>
Expand Down
6 changes: 5 additions & 1 deletion history.md
@@ -1,4 +1,8 @@
v0.1.1
#v0.1.2 / 2012-05-24

* Removed unneeded calls to `.then` to address performance degredation (#30)

#v0.1.1 / 2012-05-23

* Updated grunt
* Fixed nextTick issues for node v0.10 #32
Expand Down
6 changes: 3 additions & 3 deletions lib/index.js
Expand Up @@ -271,7 +271,7 @@ var Flow = declare(EventEmitter, {
var activation = this.agenda.pop(), rootNode = this.rootNode;
activation.used = true;
this.emit("fire", activation.rule.name, activation.match.factHash);
return when(activation.rule.fire(this, activation.match)).then(bind(this, function () {
return when(activation.rule.fire(this, activation.match)).addCallback(bind(this, function () {
if (this.__wmAltered) {
rootNode.incrementCounter();
this.__wmAltered = false;
Expand All @@ -284,7 +284,7 @@ var Flow = declare(EventEmitter, {
this.__halted = false;
return this.__loop(bind(this, function (ret, fire) {
if (!this.agenda.isEmpty() && !this.__halted) {
this.__callNext(fire).then(fire, ret.errback);
this.__callNext(fire).addCallback(fire).addErrback(ret.errback);
} else if (!this.__halted) {
nextTick(fire);
} else {
Expand All @@ -296,7 +296,7 @@ var Flow = declare(EventEmitter, {
match: function (cb) {
return this.__loop(bind(this, function (ret, fire) {
if (!this.agenda.isEmpty()) {
this.__callNext(fire).then(fire, ret.errback);
this.__callNext(fire).addCallback(fire).addErrback(ret.errback);
} else {
ret.callback();
}
Expand Down
5 changes: 2 additions & 3 deletions lib/rule.js
Expand Up @@ -2,7 +2,6 @@
var extd = require("./extended"),
isArray = extd.isArray,
Promise = extd.Promise,
when = extd.when,
declare = extd.declare,
parser = require("./parser"),
pattern = require("./pattern"),
Expand Down Expand Up @@ -105,9 +104,9 @@ var Rule = declare({
var ret = new Promise(), cb = this.cb;
try {
if (cb.length === 3) {
this.cb.call(flow, match.factHash, flow, ret.classic);
cb.call(flow, match.factHash, flow, ret.classic);
} else {
when(this.cb.call(flow, match.factHash, flow)).then(ret.callback, ret.errback);
return cb.call(flow, match.factHash, flow);
}
} catch (e) {
ret.errback(e);
Expand Down

0 comments on commit 8aa530a

Please sign in to comment.