LiquidLava class system performance (v3)

Revision 3 of this benchmark created by kogarashisan1 on


Description

Performance of LiquidLava generated classes is equal to their hand-written analogues.

You can see that construction is slower - that is due to the following line, which is present in generated constructors, and not present in native:

var r=Lava.ClassManager.getClassData('...').references;

When size of classes increase - this line plays less role, and construction speed becomes equal to native.

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/mootools/1.5.1/mootools-yui-compressed.js"></script>
<script src="http://lava-framework.com/lib/lava-master-DEBUG.js"></script>

<script>
// create classes in traditional way
function NativeParentClass() { this.counter = 0; }
NativeParentClass.prototype.parentMethod = function() { this.counter++; }

function NativeChildClass() {}
NativeChildClass.prototype = new NativeParentClass();
NativeChildClass.prototype.childMethod = function() { this.parentMethod(); }

var NativeInstance = new NativeChildClass();

// Create classes via Lava.ClassManager
Lava.ClassManager.registerRootNamespace('window', window);
Lava.ClassManager.define(
'window.LavaParentClass',
{
    counter: 0,
    parentMethod: function() { this.counter++; }
});

Lava.ClassManager.define(
'window.LavaChildClass',
{
    Extends: 'window.LavaParentClass',
    childMethod: function() { this.parentMethod(); }
});

var LavaInstance = new LavaChildClass();

// the same classes, but generated on server
Lava.ClassManager.loadClass({
        name: "LavaServerParent",
        path: "window.LavaServerParent",
        level: 0,
        "extends": null,
        "implements": [],
        hierarchy_paths: ["window.LavaServerParent"],
        parent_class_data: null,
        prototype_generator: function(cd,p) {
                var r=cd.references,
                s=cd.shared;
                p.Class = cd;
                p.counter = 0;
                p.parentMethod = r[0];
        },
        shared: {},
        references: [function () { this.counter++; }],
        constructor: function() {
                var r=Lava.ClassManager.getClassData('window.LavaServerParent').references;
        }
});

Lava.ClassManager.loadClass({
        name: "LavaServerChild",
        path: "window.LavaServerChild",
        level: 1,
        "extends": "window.LavaServerParent",
        "implements": [],
        hierarchy_paths: [
                "window.LavaServerParent",
                "window.LavaServerChild"
        ],
        parent_class_data: null,
        prototype_generator: function(cd,p) {
                var r=cd.references,
                s=cd.shared;
                p.Class = cd;
                p.childMethod = r[1];
                p.counter = 0;
                p.parentMethod = r[0];
        },
        shared: {},
        references: [function () { this.parentMethod(); }],
        constructor: function() {
                var r=Lava.ClassManager.getClassData('window.LavaServerChild').references;
        }
});

var ServerInstance = new LavaServerChild();
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Native class creation
for (var i = 0; i < 10000; i++) {
    new NativeChildClass()
}
ready
Lava class creation (client generated class)
for (var i = 0; i < 10000; i++) {
    new LavaChildClass()
}
ready
Lava class creation (server-side generated class)
for (var i = 0; i < 10000; i++) {
    new LavaServerChild()
}
ready
Native method call
for (var i = 0; i < 20000; i++) {
    NativeInstance.childMethod()
}
ready
Lava method call (client generated class)
for (var i = 0; i < 20000; i++) {
    LavaInstance.childMethod()
}
ready
Lava method call (server generated class)
for (var i = 0; i < 20000; i++) {
    ServerInstance.childMethod()
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 3: published by kogarashisan1 on
  • Revision 9: published by Vyacheslav Egorov on
  • Revision 10: published by kogarashisan1 on