Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/bokeh/util/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
#-----------------------------------------------------------------------------
from __future__ import annotations

from bokeh.core.types import ID
from bokeh.settings import settings

import logging # isort:skip

log = logging.getLogger(__name__)

#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -247,7 +251,7 @@ def convert(array: npt.NDArray[Any]) -> npt.NDArray[Any]:
return array

def make_id() -> ID:
''' Return a new unique ID for a Bokeh object.
""" Return a new unique ID for a Bokeh object.

Normally this function will return simple monotonically increasing integer
IDs (as strings) for identifying Bokeh objects within a Document. However,
Expand All @@ -257,30 +261,29 @@ def make_id() -> ID:
Returns:
str

'''
"""
global _simple_id

from ..core.types import ID

if settings.simple_ids():
# Inline reference to ID to avoid dynamic import and reduce function call overhead.
with _simple_id_lock:
_simple_id += 1
# Direct call to ID, f-string is fast enough.
return ID(f"p{_simple_id}")
else:
return make_globally_unique_id()
# Inline make_globally_unique_id implementation to avoid extra function frame and import.
return ID(str(uuid.uuid4()))

def make_globally_unique_id() -> ID:
''' Return a globally unique UUID.
""" Return a globally unique UUID.

Some situations, e.g. id'ing dynamically created Divs in HTML documents,
always require globally unique IDs.

Returns:
str

'''
from ..core.types import ID

"""
return ID(str(uuid.uuid4()))

def make_globally_unique_css_safe_id() -> ID:
Expand Down