From 0a7b5dfb82c4822e4ad1ed66ff2174d992e089c7 Mon Sep 17 00:00:00 2001 From: "codeflash-ai[bot]" <148906541+codeflash-ai[bot]@users.noreply.github.com> Date: Tue, 28 Oct 2025 23:04:47 +0000 Subject: [PATCH] Optimize _is_visual --- src/bokeh/plotting/_renderer.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/bokeh/plotting/_renderer.py b/src/bokeh/plotting/_renderer.py index 214f745f6ac..619a9d4291f 100644 --- a/src/bokeh/plotting/_renderer.py +++ b/src/bokeh/plotting/_renderer.py @@ -10,7 +10,14 @@ #----------------------------------------------------------------------------- from __future__ import annotations +from bokeh.core.property.dataspec import ColorSpec +from bokeh.models import ColumnarDataSource, ColumnDataSource, GlyphRenderer +from bokeh.models.glyph import Glyph +from bokeh.models.plots import Plot +from bokeh.plotting._legends import pop_legend_kwarg, update_legend + import logging # isort:skip + log = logging.getLogger(__name__) #----------------------------------------------------------------------------- @@ -34,6 +41,8 @@ from ..models.glyph import Glyph from ..models.plots import Plot +_VISUAL_FEATURES = {'line', 'fill', 'hatch', 'text', 'global'} + #----------------------------------------------------------------------------- # Globals and constants #----------------------------------------------------------------------------- @@ -314,8 +323,15 @@ def _split_feature_trait(ft: str) -> tuple[str, str | None]: def _is_visual(ft: str) -> bool: """Whether a feature trait name is visual""" - feature, trait = _split_feature_trait(ft) - return feature in ('line', 'fill', 'hatch', 'text', 'global') and trait is not None + # Inline parsing for faster execution, avoiding extra call + idx = ft.find("_") + if idx == -1: + feature = ft[0] + trait = None + else: + feature = ft[:idx] + trait = ft[idx+1:] + return feature in _VISUAL_FEATURES and trait is not None _GLYPH_SOURCE_MSG = """