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

teardownMap slows perfomance drastically #595

Closed
whitecolor opened this Issue Dec 7, 2013 · 8 comments

Comments

Projects
None yet
3 participants
@whitecolor
Contributor

whitecolor commented Dec 7, 2013

In map.js there is function teardownMap added to remove _cid on orignal object.

This code calculates performance time with 1000 objects converted to can.Map, and with teardownMap it 10 times slower than without it.

            var map = new can.Map(),g
                    objects = [];

            for (var i = 0; i < 100; i++){
                objects.push({prop: 'prop', nest: {prop: 'prop', nest: {prop: 'prop'}}})
            }

            var start = new Date()

            for (var j = 0; j < 100; j++){
                map.attr('obj', objects)
            }
            var time = (new Date() - start)/1000

            // time is ten times more with tearing down than without it
            console.log('time', time)

I could add test but not sure what to check, as performance is relative.

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Dec 7, 2013

Contributor

How are you removing it exactly?

Sent from my iPhone

On Dec 7, 2013, at 5:05 AM, Alex Osh notifications@github.com wrote:

In map.js there is function teardownMap added to remove _cid on orignal object.

This code calculates performance time item with 1000 objects converted to can.Map, and with teardownMap it 10 times slower than without it.

var map = new can.Map(),
    objects = [];

for (var i = 0; i < 1000; i++){
    objects.push({prop: 'prop'})
}

var start = new Date()

map.attr('obj', objects)

var time = (new Date() - start)/1000

// time is ten times more with tearing down than without it
console.log('time', time)    

I could add test but not sure what to check, as performance is relative.


Reply to this email directly or view it on GitHub.

Contributor

justinbmeyer commented Dec 7, 2013

How are you removing it exactly?

Sent from my iPhone

On Dec 7, 2013, at 5:05 AM, Alex Osh notifications@github.com wrote:

In map.js there is function teardownMap added to remove _cid on orignal object.

This code calculates performance time item with 1000 objects converted to can.Map, and with teardownMap it 10 times slower than without it.

var map = new can.Map(),
    objects = [];

for (var i = 0; i < 1000; i++){
    objects.push({prop: 'prop'})
}

var start = new Date()

map.attr('obj', objects)

var time = (new Date() - start)/1000

// time is ten times more with tearing down than without it
console.log('time', time)    

I could add test but not sure what to check, as performance is relative.


Reply to this email directly or view it on GitHub.

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Dec 7, 2013

Contributor

You may just put return there to test, cycle itself (even empty) causes performance drop

        teardownMap = function(){
            return
            for(var cid in madeMap){
                if(madeMap[cid].added) {
                    delete madeMap[cid].obj._cid;
                }
            }
            madeMap = null;
        },
Contributor

whitecolor commented Dec 7, 2013

You may just put return there to test, cycle itself (even empty) causes performance drop

        teardownMap = function(){
            return
            for(var cid in madeMap){
                if(madeMap[cid].added) {
                    delete madeMap[cid].obj._cid;
                }
            }
            madeMap = null;
        },
@daffl

This comment has been minimized.

Show comment
Hide comment
@daffl

daffl Dec 16, 2013

Contributor

Could this be fixed via #604?

Contributor

daffl commented Dec 16, 2013

Could this be fixed via #604?

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Dec 17, 2013

Contributor

@daffl
No, I tried. I've updated my code in OP, if you try you should see the time difference (previous version was incorrect for the case and shown no difference). On my PC I have ~5 sec for version with teardownMap and ~0.1 sec for version without it.

Performance drop is significant when you have quite large array to be converted to can.List many times in a row.

I noticed that because in my application I started to experience performance issues after update from master, debugged it and found out that it was due to e767fc6 commit.

Contributor

whitecolor commented Dec 17, 2013

@daffl
No, I tried. I've updated my code in OP, if you try you should see the time difference (previous version was incorrect for the case and shown no difference). On my PC I have ~5 sec for version with teardownMap and ~0.1 sec for version without it.

Performance drop is significant when you have quite large array to be converted to can.List many times in a row.

I noticed that because in my application I started to experience performance issues after update from master, debugged it and found out that it was due to e767fc6 commit.

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Dec 18, 2013

Contributor

I've confirmed this is indeed more than 10x slower. It seems that just setting madeMap = null; is the slow part. I'm going to have to think over this one.

Contributor

justinbmeyer commented Dec 18, 2013

I've confirmed this is indeed more than 10x slower. It seems that just setting madeMap = null; is the slow part. I'm going to have to think over this one.

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Dec 18, 2013

Contributor

Ok, I figured this out. The problem is not teardownMap. The issue is that when teardownMap is removed, only 300 objects are created instead of 300000.

This is because by removing teardownMap it doesn't re-create that big List of maps, it just uses the first one created when when the big plain array is passed to .attr('obj', objects) for the first time.

Closing... however, I'm going to work on getting a benchmark workflow into canjs.

Contributor

justinbmeyer commented Dec 18, 2013

Ok, I figured this out. The problem is not teardownMap. The issue is that when teardownMap is removed, only 300 objects are created instead of 300000.

This is because by removing teardownMap it doesn't re-create that big List of maps, it just uses the first one created when when the big plain array is passed to .attr('obj', objects) for the first time.

Closing... however, I'm going to work on getting a benchmark workflow into canjs.

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Dec 18, 2013

Contributor

So what does this mean? After e767fc6 performance became worse obviously. If what is the a way to improve it?

Contributor

whitecolor commented Dec 18, 2013

So what does this mean? After e767fc6 performance became worse obviously. If what is the a way to improve it?

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Dec 18, 2013

Contributor

Performance did not become worse. There was a bug that made it appear faster than it was. You could get the same speed as changing your above code to:

var map = new can.Map(),
      objects = [];

            for (var i = 0; i < 100; i++){
                objects.push({prop: 'prop', nest: {prop: 'prop', nest: {prop: 'prop'}}})
            }
            var objectList = new can.List(objects)
            var start = new Date()

            for (var j = 0; j < 100; j++){
                map.attr('obj', objectList)
            }
            var time = (new Date() - start)/1000

            // time is ten times more with tearing down than without it
            console.log('time', time)

This was added to solve #521

Contributor

justinbmeyer commented Dec 18, 2013

Performance did not become worse. There was a bug that made it appear faster than it was. You could get the same speed as changing your above code to:

var map = new can.Map(),
      objects = [];

            for (var i = 0; i < 100; i++){
                objects.push({prop: 'prop', nest: {prop: 'prop', nest: {prop: 'prop'}}})
            }
            var objectList = new can.List(objects)
            var start = new Date()

            for (var j = 0; j < 100; j++){
                map.attr('obj', objectList)
            }
            var time = (new Date() - start)/1000

            // time is ten times more with tearing down than without it
            console.log('time', time)

This was added to solve #521

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