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

teardownMap slows perfomance drastically #595

Closed
wclr opened this issue Dec 7, 2013 · 8 comments
Closed

teardownMap slows perfomance drastically #595

wclr opened this issue Dec 7, 2013 · 8 comments
Milestone

Comments

@wclr
Copy link
Contributor

wclr 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
Copy link
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.

@wclr
Copy link
Contributor Author

wclr 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
Copy link
Contributor

daffl commented Dec 16, 2013

Could this be fixed via #604?

@wclr
Copy link
Contributor Author

wclr 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
Copy link
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.

@justinbmeyer
Copy link
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.

@wclr
Copy link
Contributor Author

wclr 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
Copy link
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

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

No branches or pull requests

3 participants