Skip to content

perf: legend/decoration path re-expands the compact categorical colour vector (all renderers) #732

Description

@timtreis

Following #731 (points kept colour as codes+palette): the shared legend/decoration path still expands the compact pd.Categorical (codes + tiny hex palette) to an O(n_elements) object array once per render — for points, shapes and labels.

Three spots, each only needs the k categories:

  • _want_decorations (render.py:133): np.asarray(color_vector) + O(n) == scan → use .categories/.codes.
  • ColorSpec.make_palette (_color.py:754): dict.fromkeys(full_vector) + pd.Categorical rebuild + n-mask → .categories.
  • _decorate_axs (utils.py:493): builds an n-row DataFrame then drop_duplicates to recover a k-sized cat→colour dict that already exists upstream (_color.py:678).

Fix: read .categories/.codes (k entries) instead of materializing the per-element vector. Lowest-effort, benefits all three renderers at once. Must stay output-identical.

Activity

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

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