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

Optimize children selection #65

Closed
curran opened this issue Mar 15, 2017 · 1 comment
Closed

Optimize children selection #65

curran opened this issue Mar 15, 2017 · 1 comment

Comments

@curran
Copy link
Owner

curran commented Mar 15, 2017

I feel like this could be improved in terms of efficiency.

...
      .selectAll(children)
      .filter(belongsToMe)
...
  function children(){
    return this.children;
  }

  function belongsToMe(){
    var instance = instanceLocal.get(this);
    return instance && instance.owner === component;
  }

The filtering could be done inside children, something like this:

  function children(){
    var mine = [];
    for(var i = 0; i < this.children.length; i++){
      if(this.children[i].tagName === tagName){ // Could check class too
        var instance = instanceLocal.get(this.children[i]);
        if(instance && instance.owner === component){
          mine.push(this)
        }
      }
    }
    return mine;
  }
@curran
Copy link
Owner Author

curran commented Mar 15, 2017

Some of the performance losses I'm seeing in the Chrome profiler may be coming from this local.get code that walks up the DOM tree: https://github.com/d3/d3-selection/blob/master/src/local.js#L15

Maybe better to just use a property on the DOM, like __instance__, as we're only using one local?

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

1 participant