Skip to content

Repeated x value calculations in updateDatasets #3211

@desowin

Description

@desowin

updateDatasets function calls update() on every dataset controller which in turn loops on all points and calls updateElement(). Update element calculates x using xScale.getPixelForValue().

If there is a chart with M (example: 12) datasets (N points each, example: 4000) sharing the same label then exactly the same value x gets callculated M times for every updateDatasets() call. This results in O(N*M) calls to getPixelForValue(). As the x values are the same for all datasets it should be possible to optimize this to O(N) calls to getPixelForValue().

Performance improvement would be especially visible when time scale is used, as it calls moment.js diff() function. In example (M=12, N=4000) built-in Chrome profiler shows over 40% of cpu usage for diff() function.

This optimization would require code refactoring. What would be the best way to achieve the goal?

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