{"action":"created","issue":{"url":"https://api.github.com/repos/chartjs/Chart.js/issues/4865","repository_url":"https://api.github.com/repos/chartjs/Chart.js","labels_url":"https://api.github.com/repos/chartjs/Chart.js/issues/4865/labels{/name}","comments_url":"https://api.github.com/repos/chartjs/Chart.js/issues/4865/comments","events_url":"https://api.github.com/repos/chartjs/Chart.js/issues/4865/events","html_url":"https://github.com/chartjs/Chart.js/issues/4865","id":266718867,"number":4865,"title":"controller.update always called twice","user":{"login":"benmccann","id":322311,"avatar_url":"https://avatars3.githubusercontent.com/u/322311?v=4","gravatar_id":"","url":"https://api.github.com/users/benmccann","html_url":"https://github.com/benmccann","followers_url":"https://api.github.com/users/benmccann/followers","following_url":"https://api.github.com/users/benmccann/following{/other_user}","gists_url":"https://api.github.com/users/benmccann/gists{/gist_id}","starred_url":"https://api.github.com/users/benmccann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benmccann/subscriptions","organizations_url":"https://api.github.com/users/benmccann/orgs","repos_url":"https://api.github.com/users/benmccann/repos","events_url":"https://api.github.com/users/benmccann/events{/privacy}","received_events_url":"https://api.github.com/users/benmccann/received_events","type":"User","site_admin":false},"labels":[{"id":32309886,"url":"https://api.github.com/repos/chartjs/Chart.js/labels/Category:%20Enhancement","name":"Category: Enhancement","color":"84b6eb","default":false},{"id":409249702,"url":"https://api.github.com/repos/chartjs/Chart.js/labels/Needs%20Investigation","name":"Needs Investigation","color":"860145","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-10-19T04:44:06Z","updated_at":"2017-10-19T21:56:26Z","closed_at":null,"author_association":"COLLABORATOR","body":"In `src/core/core.controller.js:` we have some code that updates each controller twice. Both the call to `helpers.each` and `updateDatasets` below end up calling `controller.update` on every controller.\r\n```\r\n// Can only reset the new controllers after the scales have been updated\r\nhelpers.each(newControllers, function(controller) {\r\n\tcontroller.reset();\r\n});\r\n\r\nme.updateDatasets();\r\n```\r\n\r\nThe source for `controller.reset` calls `controller.update`:\r\n```\r\nreset: function() {\r\n\tthis.update(true);\r\n},\r\n```\r\n\r\nAnd `updateDatasets` calls `updateDataset` which calls `controller.update`:\r\n```\r\nupdateDatasets: function() {\r\n\tvar me = this;\r\n\r\n\tif (plugins.notify(me, 'beforeDatasetsUpdate') === false) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tfor (var i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {\r\n\t\tme.updateDataset(i);\r\n\t}\r\n\r\n\tplugins.notify(me, 'afterDatasetsUpdate');\r\n},\r\nupdateDataset: function(index) {\r\n\tvar me = this;\r\n\tvar meta = me.getDatasetMeta(index);\r\n\tvar args = {\r\n\t\tmeta: meta,\r\n\t\tindex: index\r\n\t};\r\n\r\n\tif (plugins.notify(me, 'beforeDatasetUpdate', [args]) === false) {\r\n\t\treturn;\r\n\t}\r\n\r\n\tmeta.controller.update();\r\n\r\n\tplugins.notify(me, 'afterDatasetUpdate', [args]);\r\n},\r\n```\r\n\r\nSo we end up calling `controller.update` twice in a row every time we update a chart, which seems like a fairly expensive operation to duplicate. I'm wondering if we can improve performance by removing one of these."},"comment":{"url":"https://api.github.com/repos/chartjs/Chart.js/issues/comments/338049372","html_url":"https://github.com/chartjs/Chart.js/issues/4865#issuecomment-338049372","issue_url":"https://api.github.com/repos/chartjs/Chart.js/issues/4865","id":338049372,"user":{"login":"etimberg","id":6757853,"avatar_url":"https://avatars3.githubusercontent.com/u/6757853?v=4","gravatar_id":"","url":"https://api.github.com/users/etimberg","html_url":"https://github.com/etimberg","followers_url":"https://api.github.com/users/etimberg/followers","following_url":"https://api.github.com/users/etimberg/following{/other_user}","gists_url":"https://api.github.com/users/etimberg/gists{/gist_id}","starred_url":"https://api.github.com/users/etimberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etimberg/subscriptions","organizations_url":"https://api.github.com/users/etimberg/orgs","repos_url":"https://api.github.com/users/etimberg/repos","events_url":"https://api.github.com/users/etimberg/events{/privacy}","received_events_url":"https://api.github.com/users/etimberg/received_events","type":"User","site_admin":false},"created_at":"2017-10-19T21:56:26Z","updated_at":"2017-10-19T21:56:26Z","author_association":"OWNER","body":"@benmccann you're right. We can optimize away the reset if the chart is not animating."}}
{"actor":{"display_login":"etimberg"}}