Fig.add_vrect( ) plots slowly

Hi, I’m trying to add a series of boxes to a plot and it’s taking quite a while to draw depending on how many are drawn. Wondering if anyone knows of a faster method to do this. Reproducible code below. My actual array has >2k elements, and this can take several minutes to finish drawing. Thanks for any help you can provide!

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

num = 500
x = np.arange(num)
y = np.random.rand(num)

start_time = time.time()

fig = go.Figure()
fig.add_trace(go.Scattergl(x=x, y=y))

# Positive derivative mask
s = pd.Series(np.diff(y)>0)
# Get start/end locations of True sections
ranges = np.vstack([s[s & (s.shift(1, fill_value=False) == False)].index.values, 
                    s[s & (s.shift(-1, fill_value=False) == False)].index.values]).T
# Offset to center on indices
starts = ranges[:, 0] - 0.5 
ends = ranges[:, 1] + 0.5

# Initialize list to hold draw times of each rectange
times = []

# Draw rectangles for each section of continuous True's in the `s` array
for s, e in zip(starts, ends):
    current_start = time.time()
    fig.add_vrect(x0=s, x1=e, fillcolor='red', opacity=0.4, line_width=0)
    current_end = time.time()
    times.append(np.round(current_end - current_start,4)) 

# Full draw time
end_time = time.time()
full_time = np.round(end_time - start_time, 2)

# Show vrect figure

# Plot draw times
fig2 = go.Figure()
fig2.add_trace(go.Scattergl(x=np.arange(len(times)), y=times))
fig2.update_layout(title=f'Total draw time = {full_time} secs', xaxis_title='Rectangle number', yaxis_title='Draw time (s)')