Skip to content

Performance degradation in 1.0? #353

Closed
@bmaranville

Description

@bmaranville

In the previous version, writing an image the first time with kaleido takes a little while (about 1 second), but further calls to write_image go much faster (hundredths of a second!)

In version 1.0.0, calling fig.write_image("plot.png") seems to take a fixed amount of time (> 1 second) for every call, with no speedup on subsequent calls.
(tests were all done on an Ubuntu 20.04 system with Chrome installed)

To reproduce:

import importlib.metadata
from time import perf_counter
import plotly.graph_objects as go
import kaleido
import numpy as np

def make_and_save_plot(filename):
    start_time = perf_counter()
    fig = go.Figure()
    x = np.linspace(0, 10, 100)
    y = np.random.random(100)
    fig.add_trace(go.Scatter(x=x, y=y, mode="lines"))
    fig.write_image(filename)
    end_time = perf_counter()
    print(f"Plot saved to {filename} in {end_time - start_time:.2f} seconds.")

print(f"Using Kaleido version: {importlib.metadata.version('kaleido')}")
print(f"Using Plotly version: {importlib.metadata.version('plotly')}")

make_and_save_plot("test-plot.png")
# repeat the plot creation to ensure it works multiple times
make_and_save_plot("test-plot-again.png")
make_and_save_plot("test-plot-again-again.png")

Results: kaleido==0.2.1

Using Kaleido version: 0.2.1
Using Plotly version: 6.2.0
/tmp/kal/check_kaledio_speed.py:13: DeprecationWarning:

Support for Kaleido versions less than 1.0.0 is deprecated and will be removed after September 2025.
Please upgrade Kaleido to version 1.0.0 or greater (pip install 'kaleido>=1.0.0' or pip install 'plotly[kaleido]').

Plot saved to test-plot.png in 1.07 seconds.
Plot saved to test-plot-again.png in 0.04 seconds.
Plot saved to test-plot-again-again.png in 0.04 seconds.

Results: kaleido==1.0.0

Using Kaleido version: 1.0.0
Using Plotly version: 6.2.0
Plot saved to test-plot.png in 1.73 seconds.
Plot saved to test-plot-again.png in 1.72 seconds.
Plot saved to test-plot-again-again.png in 1.67 seconds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions