highcharts-for-python / highcharts-stock

Python wrapper for the Highcharts Stock data visualization library.
https://stock-docs.highchartspython.com
Other
24 stars 3 forks source link

Series construction is very slow #65

Open nishikantparmariam opened 1 month ago

nishikantparmariam commented 1 month ago

Description

Construction of series objects is very slow even for array input. Our use-case requires adding multiple series to chart having ~10k points each. A single series seems to take 3 seconds.

Reproducer

from datetime import datetime
from highcharts_stock.chart import Chart
from highcharts_stock.highcharts import AreaSplineRangeSeries, LineSeries

x = list(map(datetime.fromtimestamp, range(630892800, 1686787200, 86400)))[:10000]
low = list(range(len(x)))
high = list(range(500, 500 + len(x)))
data = list(zip(x, low, high))
%%time

chart = Chart()
chart.add_series(AreaSplineRangeSeries(data=data))

image

Version

highcharts-stock == 1.7.0 highcharts-core == 1.8.2

hcpchris commented 1 month ago

Thanks, @nishikantparmariam , and sorry you're running into some slow performance here. One question: Are you running this in a context where you have NumPy installed?

We introduced some major performance improvements awhile back that have a soft dependency on NumPy (i.e. if NumPy is available in the environment, it should result in significant performance improvements) If however you are seeing this poor performance in an environment where NumPy is present, then that will require some further investigation to see what's happening.

nishikantparmariam commented 1 month ago

Yes, numpy is present in my virtual env.

hcpchris commented 1 month ago

Hmm - thanks for confirming that. I'll need to look into this, because if NumPy is present in your environment:

  1. Series construction should be vectorized.
  2. Serialization of series via .to_js_literal() should create a list of lists rather than a list of dict if the data points are not utilizing "special" properties.

All of which should provide a very significant performance boost. So this suggests that there's a bug somewhere in this that needs to get investigated / resolved.