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 2 commits 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 referenced this pull request in odoo-dev/odoo 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 
https://github.com/chartjs/Chart.js/pull/11836
it's still not approved

i will need to test on  a staging env (real data) to be coherent.
@NotTsunami
Copy link

Would love to see this PR move forward

@jwedel
Copy link
Author

jwedel commented Oct 23, 2024

Would love to see this PR move forward

Hi, me, too.

But I have to be honest, this code base is really giving me a hard time.

First, I had this problem that it only did show the first error and stops. Therfore, I temporarily added stopOnSpecFailure: false which then showed me all the existing failures.

Second, I just can't get the tests running in Intellij. They only run via node script (e.g. test-ci-karma). When starting the test in IntelliJ, I get:

Karma v 6.4.1 - connected; test: karma_error You need to include some adapter that implements __karma__.start method!;

This is so annoying, I can only use fit/fdescribe to run single test, and worst thing, I can't debug the code. I tried lots of console debugging but it is a huge waste of time. I don't know if no one uses debugging or if my local set-up is just broken.

If anyone could help me getting a setup (preferably in IntelliJ/WebStorm) to debug single test cases, then I would try to continue getting this PR done.

The current problem is, that there some edge cases that do not work anymore. E.g. removing or shuffeling datasets. This is something we don't do in our application without rebuilding this whole chart from scratch so this "issue" does not affect us but it let the tests fail. I started implementing a rebuildMetasets method that is called once during update to handle all the cases but something breaks and I am blind on this.

Short disclaimer: I'm off on vacation from tomorrow and will be able to continue in 8-9 days, if anyone is able to help.

@jwedel
Copy link
Author

jwedel commented Nov 18, 2024

@kurkle Looks better now, Windows build is green, linux not... weird. Is there a chance to see the image diff files?

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
4 participants