dagrejs / dagre-d3

A D3-based renderer for Dagre
MIT License
2.85k stars 587 forks source link

Logging causes performance problem #38

Open kiilki opened 10 years ago

kiilki commented 10 years ago

We are using dagre in our project and having performance challenges with very large graphs. When profiling the cause for it we noticed that dagre functions seems to go through time function:

function time(name, func) {
  return function() {
    var start = new Date().getTime();
    try {
      return func.apply(null, arguments);
    } finally {
       log(1, name + ' time: ' + (new Date().getTime() - start) + 'ms');
    }
  };

I would guess that this wrapper function is initially done for development purposes to log function durations but it is left, maybe accidentially, without flags to production version.

According the following 'cleaning' increases performance 40%. So maybe you should check whether Date variable defs and Date comparing could be flagged off in the production version?

time(name, func) {
  return function() {
    try { return func.apply(null, arguments);  } 
  };
}
cpettitt commented 10 years ago

I'm totally fine with adding a guard around the Date calls. There's no reason to make them if the logging level is too low. I'm happy to take this as a pull request. Otherwise I can probably knock this out sometime this weekend.

kiilki commented 10 years ago

I leave this for you as I did not find easily how you generally have implemented guards and yet implementing this by yourself is easier than reviewing my proposal :-). Thanks for quick reply.

Rytyka commented 6 years ago

Hi, Any updates on this issue?