Skip to content

feat: _as_dict=True mode for high-performance figure construction#5515

Open
AlonSpivack wants to merge 1 commit intoplotly:mainfrom
AlonSpivack:feat/as-dict-mode
Open

feat: _as_dict=True mode for high-performance figure construction#5515
AlonSpivack wants to merge 1 commit intoplotly:mainfrom
AlonSpivack:feat/as-dict-mode

Conversation

@AlonSpivack
Copy link

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the code generator and not the generated files.
  • I have added tests or modified existing tests.
  • For a new feature, I have added documentation examples (please see the doc checklist as well).
  • I have added a CHANGELOG entry if changing anything substantial.
  • For a new feature or a change in behavior, I have updated the relevant docstrings in the code.

Description

Adds _as_dict=True parameter to trace constructors and go.Figure for faster figure construction when validation is not needed.

When _as_dict=True:

  1. Trace constructors return plain dicts with auto-injected type — no validation, no object creation
  2. Figure constructor stores data/layout as raw lists/dicts — no deepcopy, no validators
  3. Methods (add_traces, update_layout, add_vline, etc.) have fast paths that directly modify internal structures

Limitations

  • add_vline/add_hline assume single-plot figures (row/col ignored)
  • No validation — invalid properties pass through silently

Benchmarks

Operation Speedup
Trace creation ~26x
Figure creation ~52x
Add traces ~36x
Add vline ~90,000x

Closes #5514

Add _as_dict=True parameter to trace constructors and go.Figure for
~4-6x faster figure construction when validation is not needed.

Fast paths added for:
- BasePlotlyType.__new__ / BaseTraceType.__new__
- BaseFigure.__init__, .data, .layout, .add_traces, .update_layout
- BaseFigure._add_annotation_like, ._process_multiple_axis_spanning_shapes
@AlonSpivack
Copy link
Author

Implementation for #5514.
Discussion about the API naming (_as_dict vs as_dict)
is happening on the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]: Add _as_dict=True to graph_objects and go.Figure for 26x-11,300x faster figure construction

1 participant

Comments