Performance issue - add_vlines
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 45/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- python
研究方向
首先,使用 Plotly 5.24.1 或 6.0.0rc0 執行提供的 Python 重現程式碼,並比較五個子圖中使用與不使用 add_vline 時的圖形建立過程。追蹤 add_vline 路徑,以找出造成時間差的重複工作;在保留 vline 輸出的同時,大幅縮短所報告案例的建立時間,即視為完成。
由索引模型根據 Issue 內容生成。
描述
Issue: When vlines are added to a figure with subplots, the performance is much worse than without adding them.
Here is the code to reproduce the problem with 30 vlines vs. no vlines:
import numpy as np
import plotly.graph_objects as go
from dash import Dash, dcc, html
from plotly.subplots import make_subplots
import time
def generate_sample_data(n_traces=30, n_points=1000):
x = np.linspace(0, 100, n_points)
traces_data = []
for i in range(n_traces):
y = np.sin(x + i/10) + np.random.normal(0, 0.1, n_points)
traces_data.append((x, y))
vline_positions = np.random.choice(x, size=30, replace=False)
return traces_data, vline_positions
def create_figure(traces_data, vline_positions=None, add_vlines=True):
fig = make_subplots(
rows=5,
cols=1,
shared_xaxes=True,
vertical_spacing=0.02
)
# add all traces to each subplot
for row in range(1, 6):
for i, (x, y) in enumerate(traces_data):
fig.add_trace(
go.Scatter(
x=x,
y=y,
name=f'Trace {i+1}',
mode='lines',
line=dict(width=1),
showlegend=False
),
row=row,
col=1
)
# add vertical lines
if add_vlines and vline_positions is not None:
for x_pos in vline_positions:
for row in range(1, 6):
fig.add_vline(
x=x_pos,
line_width=1,
line_dash="dash",
line_color="gray",
row=row,
col=1
)
fig.update_layout(
title="Performance Test: vlines vs no vlines",
showlegend=False,
width=1200,
height=1500,
template="plotly_white",
)
# y-axis titles
for i in range(1, 6):
fig.update_yaxes(title_text=f"Y Axis {i}", row=i, col=1)
return fig
# initialize data
traces_data, vline_positions = generate_sample_data()
# figure creation without vlines
start_time = time.time()
fig_no_vlines = create_figure(traces_data, vline_positions, add_vlines=False)
time_no_vlines = time.time() - start_time
# figure creation with vlines
start_time = time.time()
fig_with_vlines = create_figure(traces_data, vline_positions, add_vlines=True)
time_with_vlines = time.time() - start_time
app = Dash(__name__)
app.layout = html.Div([
html.H1("Plotly vlines performance test"),
html.Div([
html.P(f"Time to create figure without vlines: {time_no_vlines:.4f} seconds"),
html.P(f"Time to create figure with vlines: {time_with_vlines:.4f} seconds"),
html.P(f"Difference: {(time_with_vlines - time_no_vlines):.4f} seconds")
]),
html.H2("Figure with vlines"),
dcc.Graph(figure=fig_with_vlines),
html.H2("Figure without vlines"),
dcc.Graph(figure=fig_no_vlines)
])
if __name__ == '__main__':
app.run(debug=False)
The results of running it on my laptop are:
Plotly vlines performance test
Time to create figure without vlines: 0.5664 seconds
Time to create figure with vlines: 7.1900 seconds
Difference: 6.6235 seconds
I'm working on a simulator of trading strategies where vlines are important in the situation with subplots (to view vales of indicators easily) - there are many more traces than in this demo code with 34 vlines and the time difference is similar.
I discovered the issue using Python 3.12.8, Plotly 5.24.1 and 6.0.0rc0, running on Windows 11 64-bit.
- 主要語言
- Python
- 星號
- 18.8k
- 分支
- 2.8k
- 平均合併
- 16 小時 26 分鐘
- 30 天內合併 PR
- 21
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
plotly/plotly.py 的其他 Issue
-
P3 size: 1 task
難度 2/5 1-3 小時 新手友好度 72/100
-
bug P1
難度 1/5 1 小時以內 新手友好度 68/100
-
feature P3
難度 2/5 1-3 小時 新手友好度 62/100
-
feature P3
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 3/5 1-2 天 新手友好度 35/100
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 74/100
bancolombia/sentinel#23 ·
-
test md 未關閉CI
難度 2/5 1-3 小時 新手友好度 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
難度 2/5 1-3 小時 新手友好度 74/100
langchain-ai/deepagents#6450 ·
-
bug client
難度 2/5 1-3 小時 新手友好度 88/100
-
難度 2/5 1-3 小時 新手友好度 74/100