Speed up Pyodide interaction dispatch ~50x (#21
Merged
Conversation
The docs ⚡ bridge dispatched every interaction event with pyodide.runPythonAsync(code-string), which parses + compiles a fresh Python code string per event — ~1.2 ms/event in WASM, the dominant per-frame cost of the Pyodide interaction path on a drag (30-60 events/sec). That's why 3D orbit / plane-drag felt sluggish in the docs vs a live Jupyter kernel. Define a pre-compiled `_awi_dispatch(fig_id, data)` function once at boot and call its PyProxy directly from the message handler (~0.02 ms/event, ~50x faster, measured end-to-end in Pyodide). The proxy is fetched lazily and cached (robust to boot-step ordering) with a runPythonAsync fallback. The Python->JS return path was already efficient (a compiled observer closure calling js.window._anywidgetPush), so no change needed there. All 12 bridge-boot tests pass.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21 +/- ##
=======================================
Coverage 90.63% 90.63%
=======================================
Files 33 33
Lines 2744 2744
=======================================
Hits 2487 2487
Misses 257 257 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The docs ⚡ bridge dispatched every interaction event with pyodide.runPythonAsync(code-string), which parses + compiles a fresh Python code string per event — ~1.2 ms/event in WASM, the dominant per-frame cost of the Pyodide interaction path on a drag (30-60 events/sec). That's why 3D orbit / plane-drag felt sluggish in the docs vs a live Jupyter kernel.
Define a pre-compiled
_awi_dispatch(fig_id, data)function once at boot and call its PyProxy directly from the message handler (~0.02 ms/event, ~50x faster, measured end-to-end in Pyodide). The proxy is fetched lazily and cached (robust to boot-step ordering) with a runPythonAsync fallback.The Python->JS return path was already efficient (a compiled observer closure calling js.window._anywidgetPush), so no change needed there.
All 12 bridge-boot tests pass.