highcharts-for-python / highcharts-core

Python wrapper for the Highcharts Core JavaScript library
https://www.highcharts.com/integrations/python
Other
58 stars 13 forks source link

Slowness in rendering Charts #186

Open nishikantparmariam opened 4 months ago

nishikantparmariam commented 4 months ago

Description

to_js_literal is very slow 19s for 4k points series causing slowness in rendering the Chart.

Same as - https://github.com/highcharts-for-python/highcharts-core/issues/51

Reproducer

import pandas as pd
import seaborn as sns
from highcharts_core.chart import Chart
from highcharts_core.options.plot_options import PlotOptions
from highcharts_core.options.series.scatter import ScatterSeries

original_df = sns.load_dataset("iris")
df = sns.load_dataset("iris")

for i in range(26):
    df = pd.concat([df, original_df])

ch = Chart.from_pandas(
    df,
    property_map={
        "x": "petal_width",
        "y": "sepal_length",
    },
    series_type="scatter",
)
%%time
js_literal = ch.to_js_literal()

image

Version

highcharts-core == 1.8.2

hcpchris commented 4 months ago

Hmm. Given your comment in https://github.com/highcharts-for-python/highcharts-stock/issues/65#issuecomment-2231065256 , this suggests that there is a bug somewhere in Highcharts for Python. Because in a context where NumPy is present/available:

  1. The internal data structure should be vectorized, and
  2. Data points should be serialized via .to_js_literal() as a list of lists (unless the data point has a property configured that precludes that).

Both of those features should contribute to a significantly faster rendering time. This will require a bit more investigation.