From b8d94bd3378f36ddc86fc62258804fd95ccc8d86 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 24 Jan 2023 13:04:10 -0500 Subject: [PATCH] Use `._pathops.slice_from_time()` for overlay intersects It's way faster since it uses a uniform time arithmetic to narrow the `numpy.searchsorted()` range before actually doing the index search B) --- piker/ui/_interaction.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/piker/ui/_interaction.py b/piker/ui/_interaction.py index a0b67aeb..229d2684 100644 --- a/piker/ui/_interaction.py +++ b/piker/ui/_interaction.py @@ -43,6 +43,7 @@ from ..log import get_logger from .._profile import Profiler from .._profile import pg_profile_enabled, ms_slower_then from ..data.types import Struct +from ..data._pathops import slice_from_time # from ._style import _min_points_to_show from ._editors import SelectRect from . import _event @@ -1230,20 +1231,22 @@ class ChartView(ViewBox): # major has later timestamp adjust minor if tdiff > 0: - y_minor_i = np.searchsorted( - minor_in_view['time'], - major_i_start_t, + slc = slice_from_time( + arr=minor_in_view, + start_t=major_i_start_t, + stop_t=major_i_start_t, ) - y_minor_intersect = minor_in_view[y_minor_i][key] + y_minor_intersect = minor_in_view[slc.start][key] profiler(f'{viz.name}@{chart_name} intersect by t') # minor has later timestamp adjust major elif tdiff < 0: - y_major_i = np.searchsorted( - major_in_view['time'], - minor_i_start_t, + slc = slice_from_time( + arr=major_in_view, + start_t=minor_i_start_t, + stop_t=minor_i_start_t, ) - y_major_intersect = major_in_view[y_major_i][key] + y_major_intersect = major_in_view[slc.start][key] profiler(f'{viz.name}@{chart_name} intersect by t')