Skip to content

perf: shrink the document every session builds on the event loop - #93

Merged
tabedzki merged 1 commit into
m-beau:devfrom
tabedzki:tabedzki/perf/session-build
Nov 11, 2026
Merged

tabedzki merged 1 commit into
m-beau:devfrom
tabedzki:tabedzki/perf/session-build

Conversation

@tabedzki

@tabedzki tabedzki commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

🤖 AI text below 🤖

Shortens the event-loop stall that every new session causes. This is the per-session stall noted as not fixed in #92.

Summary

Bokeh builds, validates, serialises and sends each session's document on the loop that also serves other sessions and /liveness. That cost scales with the number of models and the size of their data, and outline decoration made up most of the models.

 setup_bokeh_plot
-  plot.line / plot.text per outline, bank line and label    # 33 renderers, 485 models
+  one multi_line or text renderer per style                 # 9 renderers, 269 models
+  tap and box tools target only electrode and survey bars
 create_electrode_data
-  Python loop over electrodes, 16 appends each              # 93 ms
+  NumPy geometry, array columns, no per-cell validation     # 9.5 ms
 tool icons
-  decode and re-encode six PNGs per session
+  reuse cached _asset_data_uri

Evidence

Real images, 4500M memory cap, headless browser loading sessions while polling /liveness. The first session of each run is excluded. Each page uses an empty browser cache.

Worst /liveness per session dev median (max) This PR median (max)
8 CPUs, 8 sessions 0.772 s (1.022 s) 0.505 s (0.527 s)
0.25 CPU, 6 sessions 3.430 s (4.099 s) 2.037 s (2.168 s)

Median page-ready time went from 1.73 s to 1.32 s at 8 CPUs, and from 5.05 s to 3.18 s at 0.25 CPU.

Same behaviour:

  • Lines, labels, axis ranges and all electrode column values match dev on all four probe types, with nothing selected.
  • Comparing dev and this PR in a browser, the plot canvas is pixel-identical after an outline tap, electrode tap, box select, probe switch and a tap on the new probe. No page errors.
  • That browser comparison caught a regression in my first version: tapping near a shank dimmed the other outlines. Restricting the tools fixed it, and a test now covers it. Region bands and labels also no longer respond to these tools.
  • Full suite: 1011 passed, 1 xfailed. ruff check . is clean.

Not fixed: sessions are still built on the event loop, so this makes the stall shorter but doesn't remove it. A heavily contended server can still trigger the watchdog. The first session's extra cost is handled separately by #92, and each run here logged one stall warning at 0.25 CPU, the same count on dev and this PR. I didn't identify which session caused it.

Merge Danger

Door: two-way

Revert the commit. No data or format changes.

Blast Radius: plot

Every probe plot changes how it's built, and the browser now receives typed arrays for numeric electrode columns. Survey loading is covered by the test suite but wasn't part of the browser comparison.

Assisted-by: ClaudeCode:claude-opus-5-5

Each session builds, validates, serialises and sends its Bokeh document on
the loop that serves every other session and /liveness.

- Draw shank outlines, bank lines and labels with one renderer per style.
  A 4-shank document drops from 33 renderers and 485 models to 9 and 269.
- Limit tap and box-select tools to the electrode and survey-bar renderers,
  so a tap on a shared outline renderer can't dim the other outlines.
- Send numeric electrode columns as arrays, compute their geometry with
  NumPy, and skip Bokeh's per-cell check of that fixed-shape source.
- Reuse the cached data URI for tool icons instead of re-encoding six PNGs.

Assisted-by: ClaudeCode:claude-opus-5-5
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (dev@faf32d9). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@          Coverage Diff           @@
##             dev      #93   +/-   ##
======================================
  Coverage       ?   85.58%           
======================================
  Files          ?       21           
  Lines          ?     3421           
  Branches       ?        0           
======================================
  Hits           ?     2928           
  Misses         ?      493           
  Partials       ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tabedzki
tabedzki requested a review from m-beau November 7, 2026 21:15
@tabedzki
tabedzki merged commit 64afc5d into m-beau:dev Nov 11, 2026
2 checks passed
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.

2 participants