Skip to content

Reduce object creation during parsing#6758

Merged
etimberg merged 4 commits intochartjs:masterfrom
benmccann:parsing-improvement
Nov 17, 2019
Merged

Reduce object creation during parsing#6758
etimberg merged 4 commits intochartjs:masterfrom
benmccann:parsing-improvement

Conversation

@benmccann
Copy link
Contributor

This is an alternative to #6750, which does not move _parsed out of metaData

Removed addElementAndReset because of a bug. insertElements was calling updateElement via addElementAndReset and then calling _parse. However, updateElement assumes that the parsing has already happened, so these were happening in the wrong order. Also, _parse assumes the metaData is already created and stored, so there was no possible way to call addElementAndReset without causing issues. The code now calls these methods in the correct order

It also renames _val to _parsed in doughnut.

for (i = start; i < start + count; ++i) {
const element = me.createMeta(me.dataElementType);
me._cachedMeta.data.splice(i, 0, element);
me._parse(i, 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sould be more efficient to first create all, splice once, parse once, update each

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had been debating that and wasn't sure which would be more efficient. The splice is clearly more efficient the way you suggested, but we're now looping over the elements multiple times, so it wasn't clear to me which would be faster. I've updated it the way you suggested though

@etimberg etimberg merged commit f5b2b8d into chartjs:master Nov 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants