plotly / plotly/plotly.js

Performance issues with many traces compared to single traces

未关闭
#7,489 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

还没有人认领这个 Issue。

cs P1
主要语言
JavaScript
星标
18.3k
派生
2k
平均合并
2 天 12 小时
30 天内合并 PR
28

描述

Today, Plotly.js starts to stumble when generating charts with many traces, even if the total number of points is the same. This is a Python example but I believe it boils down to plotly.js.

The performance difference is stark (M4 MacBook Air):

python 100k_traces_1_point_each.py 
=== Testing 100k traces with 1 point each ===
Generating data for 100k traces with 1 point each...
Data generation took: 8.78 seconds
Creating plot...
Plot creation took: 2.47 seconds
Total time: 11.25 seconds

=== Testing 1 trace with 100k points ===
Generating data for 1 trace with 100k points...
Data generation took: 0.00 seconds
Creating plot...
Plot creation took: 0.55 seconds
Total time: 0.55 seconds

Reproduce:

import plotly.graph_objects as go
import numpy as np
import time

def test_100k_traces_1_point():
    print("=== Testing 100k traces with 1 point each ===")
    print("Generating data for 100k traces with 1 point each...")
    start_time = time.time()

    traces = []
    for i in range(100000):
        traces.append(go.Scatter(
            x=[np.random.rand()],
            y=[np.random.rand()],
            mode='markers',
            name=f'Trace {i}',
            showlegend=False
        ))

    data_gen_time = time.time() - start_time
    print(f"Data generation took: {data_gen_time:.2f} seconds")

    fig = go.Figure(data=traces)
    fig.update_layout(
        title="100k Traces - 1 Point Each (100k total points)",
        xaxis_title="X Axis",
        yaxis_title="Y Axis"
    )

    print("Creating plot...")
    start_time = time.time()
    fig.show()
    plot_time = time.time() - start_time
    print(f"Plot creation took: {plot_time:.2f} seconds")
    print(f"Total time: {data_gen_time + plot_time:.2f} seconds")

def test_1_trace_100k_points():
    print("\n=== Testing 1 trace with 100k points ===")
    print("Generating data for 1 trace with 100k points...")
    start_time = time.time()

    x_data = np.random.rand(100000)
    y_data = np.random.rand(100000)

    data_gen_time = time.time() - start_time
    print(f"Data generation took: {data_gen_time:.2f} seconds")

    trace = go.Scatter(
        x=x_data,
        y=y_data,
        mode='markers',
        name='Single Trace - 100k Points',
        marker=dict(size=2)
    )

    fig = go.Figure(data=[trace])
    fig.update_layout(
        title="1 Trace - 100k Points",
        xaxis_title="X Axis",
        yaxis_title="Y Axis"
    )

    print("Creating plot...")
    start_time = time.time()
    fig.show()
    plot_time = time.time() - start_time
    print(f"Plot creation took: {plot_time:.2f} seconds")
    print(f"Total time: {data_gen_time + plot_time:.2f} seconds")

if __name__ == "__main__":
    test_100k_traces_1_point()
    test_1_trace_100k_points()

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。