{"action":"closed","issue":{"url":"https://api.github.com/repos/d3/d3-time/issues/5","labels_url":"https://api.github.com/repos/d3/d3-time/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/d3/d3-time/issues/5/comments","events_url":"https://api.github.com/repos/d3/d3-time/issues/5/events","html_url":"https://github.com/d3/d3-time/issues/5","id":92272813,"number":5,"title":"Performance optimization for interval.count.","user":{"login":"jheer","id":202799,"avatar_url":"https://avatars.githubusercontent.com/u/202799?v=3","gravatar_id":"","url":"https://api.github.com/users/jheer","html_url":"https://github.com/jheer","followers_url":"https://api.github.com/users/jheer/followers","following_url":"https://api.github.com/users/jheer/following{/other_user}","gists_url":"https://api.github.com/users/jheer/gists{/gist_id}","starred_url":"https://api.github.com/users/jheer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jheer/subscriptions","organizations_url":"https://api.github.com/users/jheer/orgs","repos_url":"https://api.github.com/users/jheer/repos","events_url":"https://api.github.com/users/jheer/events{/privacy}","received_events_url":"https://api.github.com/users/jheer/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-01T05:23:47Z","updated_at":"2015-07-01T05:44:28Z","closed_at":"2015-07-01T05:44:28Z","body":"[Datalib](https://github.com/vega/datalib) is now using d3-time for time calculations. When creating a histogram over large-ish tables with datetime fields, the `count` method can be called many times (100,000+) to compute bin indices. The multiple object allocations (`new Date()` calls) start to add up.\r\n\r\nHow about using temp Date objects instead? For example:\r\n```\r\nvar a = new Date(),\r\n    b = new Date();\r\n\r\nif (count) interval.count = function(start, end) {\r\n  a.setTime(+start), b.setTime(+end);\r\n  floori(a), floori(b);\r\n  return Math.floor(count(a, b));\r\n};\r\n```\r\n(The temp dates might be moved out of the enclosing `newInterval` function scope.)\r\n\r\nSome quick and dirty benchmarks in Chrome (Mac OS) suggest that this can reduce the running time by about 30%."}}