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

Slow assertion of predefined objects #151

Open
Kauzig opened this issue Apr 1, 2015 · 2 comments
Open

Slow assertion of predefined objects #151

Kauzig opened this issue Apr 1, 2015 · 2 comments

Comments

@Kauzig
Copy link

Kauzig commented Apr 1, 2015

In my nools rule language file I have defined the following object:

define MyObject {
    id : '',
    value : 'NO_VALUE',
    parameters : { },
    constructor : function(id, value, parameters) {
        this.id = id;
        this.value = value;
        this.parameters = parameters;
    }
}

I have noticed that adding instances of these objects takes a notably long time. Executing the following testing code,

var _flow = this._nools.compile(noolsDSL, {name: "adaptationRules"});
var _MyObject = _flow.getDefined("MyObject");
var _currentSession = this._flow.getSession();

var addIntTime = Date.now() / 1000;
for (var i = 1; i < 10000; i++) {
    _currentSession.assert(i);
}
console.log("Add 10000 integers time: "+(Date.now() / 1000 - addIntTime));

var addStringsTime = Date.now() / 1000;
for (var i = 1; i < 10000; i++) {
    _currentSession.assert("foo");
}
console.log("Add 10000 strings time: "+(Date.now() / 1000 - addStringsTime));

var addArrayTime = Date.now() / 1000;
for (var i = 1; i < 10000; i++) {
    _currentSession.assert([1, 2, 3]);
}
console.log("Add 10000 arrays time: "+(Date.now() / 1000 - addArrayTime));

var addObjectTime = Date.now() / 1000;
for (var i = 1; i < 10000; i++) {
    _currentSession.assert({foo: "bar", baz: [42, "foobar", 24]});
}
console.log("Add 10000 objects time: "+(Date.now() / 1000 - addObjectTime));

var addDefinedObjectTime = Date.now() / 1000;
for (var i = 1; i < 10; i++) {
    _currentSession.assert(new _MyObject("foo", "bar", {foo: "baz"}));
}
console.log("Add 10 predefined objects time: "+(Date.now() / 1000 - addDefinedObjectTime));

produced these times for asserting different data types.

Add 10000 integers time: 0.06599998474121094
Add 10000 strings time: 0.06400012969970703
Add 10000 arrays time: 0.06499981880187988
Add 10000 objects time: 0.0690000057220459
Add 10 defined objects time: 7.391999959945679
@Kauzig
Copy link
Author

Kauzig commented Apr 1, 2015

Here are the times for individual objects:

Add predefined object time: 0.002000093460083008
Add predefined object time: 0.007999897003173828
Add predefined object time: 0.015000104904174805
Add predefined object time: 0.06499981880187988
Add predefined object time: 0.14400005340576172
Add predefined object time: 0.39100003242492676
Add predefined object time: 1.003000020980835
Add predefined object time: 3.2190001010894775
Add predefined object time: 4.48799991607666
Add 10 predefined objects time: 9.337000131607056

Seems to be an exponentially increase.

@Kauzig
Copy link
Author

Kauzig commented Oct 16, 2015

Further research did reveal that not the type of the object is the cause for the long assertion times, rather the following rule:

rule "4cde00e8-4118-46a5-815c-32ec47f76a9f" {
    when {
        c1 : MyObject;
        c2 : MyObject;
        c3 : MyObject;
        c4 : MyObject;
        c5 : MyObject;
        c6 : MyObject;
        c7 : MyObject c1.id == 'ID1' && c1.value == '127' && (c2.id == 'ID1' && c2.value == '124' || c2.id == 'ID1' && c2.value == '125') && (c3.id == 'ID1' && c3.value == '128' || c3.id == 'ID1' && c3.value == '125') && c4.id == 'ID2' && c4.parameters['P1'] == 'PV1' && c4.value < '20.0' && c5.id == 'ID3' && c5.value == 'FEATURE_PHONE' && c6.id == 'ID4' && c6.value == '13.13021' && c7.id == 'ID5' && c7.value == '52.39346';
    } then {
        emit("select", "126", facts);
    }
} 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants