Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improves chart update performance for a large number of datasets #11836

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jwedel
Copy link

@jwedel jwedel commented Jul 17, 2024

This PR improves the chart update performance drastically by replacing a nested loop O(n^2) by an index access O(1) in a method that is called a lot during chart update.

On a reference system (Mac M1 Pro), the fix enables

  • 10.000 datasets instead of 2.500 with acceptable performance
  • including zooming, panning and hovering

Fixes #11814 partly

@jwedel
Copy link
Author

jwedel commented Jul 18, 2024

The tests are failing, I will have look. The problem ist, that I have a little trouble due to this issue ( #11828 ) as I always have test failures and thus its is hard to spot which ones are related to my change.

@etimberg
Copy link
Member

@jwedel the tests that are failing don't seem to be image based tests. It looks like they're failing in some specific cases when datasets are inserted

@jwedel
Copy link
Author

jwedel commented Jul 18, 2024

@etimberg yes, I know.

The problem is, that I ran the tests on clean master and had 2 failing tests.

Then, implemented the fix and also got 2 failed tests.

I just realized, that karma stops on the first failing test, and it runs on two browsers, so just looking at the failing test number does not help in my special case (as I assumed).

RaoufGhrissi added a commit to odoo-dev/odoo that referenced this pull request Aug 14, 2024
from perf doc : https://github.com/chartjs/Chart.js/blob/b9c01414bac867310d192da676c78e8e269f7d8b/docs/general/performance.md?plain=1

PARSING:

we can optimize by removing parsing, if we send date in the valid format and ordered, we can set parsing to false and save some time

following the doc: https://www.chartjs.org/docs/latest/samples/bar/stacked-groups.html
and testing with (array of object (x, y) instead of array of int)

testing at odoo with parsing = false,

there is a small problem, i'm still looking why the count is not well displayed (fyi, it's well computed as you can see in the y axis)

Data normalization

when parsing, i used unique and sorted data, so it should work with normalized: true

Decimation (https://github.com/chartjs/Chart.js/blob/b9c01414bac867310d192da676c78e8e269f7d8b/docs/configuration/decimation.md)

can't be acheived as our labels are not linear or time, we use stages (string)

Disable Animations

for large data

i'm also wondering if we disable the view for large data. it doesn't make sense to show tens of thousands of data points on a graph that is only a few hundred pixels wide.

it was crushing, and sometimes loaded in 160 seconds, now it's done in around ~ 70 seconds, but as you can see it's not readable at all

I also found an open issue on github, and someone tried to solve it 
chartjs/Chart.js#11836
it's still not approved

i will need to test on  a staging env (real data) to be coherent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Chart update performance with many datasets
2 participants