Skip to content

controller.update always called twice #4865

Description

@benmccann

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.

// Can only reset the new controllers after the scales have been updated
helpers.each(newControllers, function(controller) {
	controller.reset();
});

me.updateDatasets();

The source for controller.reset calls controller.update:

reset: function() {
	this.update(true);
},

And updateDatasets calls updateDataset which calls controller.update:

updateDatasets: function() {
	var me = this;

	if (plugins.notify(me, 'beforeDatasetsUpdate') === false) {
		return;
	}

	for (var i = 0, ilen = me.data.datasets.length; i < ilen; ++i) {
		me.updateDataset(i);
	}

	plugins.notify(me, 'afterDatasetsUpdate');
},
updateDataset: function(index) {
	var me = this;
	var meta = me.getDatasetMeta(index);
	var args = {
		meta: meta,
		index: index
	};

	if (plugins.notify(me, 'beforeDatasetUpdate', [args]) === false) {
		return;
	}

	meta.controller.update();

	plugins.notify(me, 'afterDatasetUpdate', [args]);
},

So 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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions