Slow performance with set path attr #616

Open
caiiiycuk opened this Issue Sep 5, 2012 · 1 comment

Comments

Projects
None yet
2 participants

I have code, like this:

// path is absolute path string, like 'M10,10L20,20...Z'
function render(path) {
   this.element.attr('path', path);
}

I often update this path and i have ugly performance in Firefox 15.0. I profile the code, and problem is on line 4127:

                    case "path":
                        if (o.type == "path") {
                            $(node, {d: value ? attrs.path = R._pathToAbsolute(value) : "M0,0"}); // HERE
                            o._.dirty = 1;
                            if (o._.arrows) {
                                "startString" in o._.arrows && addArrow(o, o._.arrows.startString);
                                "endString" in o._.arrows && addArrow(o, o._.arrows.endString, 1);
                            }
                        }
                        break;

Method R._pathToAbsolute(value) works slowly and useless, cause input value === output value. So i change this line with:

$(node, {d: value ? attrs.path = value : "M0,0"});

And i have significant performance improve.

I have also noticed slow performance in firefox when setting the path component of the attr function. However it is incorrect to assume that the input == output in your statement. They are similar yes, but not always identical. A direct replacement will not always work.

That said, I reworked what I was setting the path attr to so that the R.pathToAbsolute() result became the same as value, then I removed the function call as you indicated. I also got a large performance gain.

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