shiny-py-optimize
БесплатноБез исполняемых скриптовНе проверенDiagnose and fix performance problems in Shiny for Python apps — slow startup, sluggish interactions, blocking operations, and apps that struggle beyond a…
от posit-dev★ 578 звёзд на GitHubОб этом скилле
Optimizing Shiny for Python App Performance
Make an existing Shiny for Python app faster without changing what it does. The typical user has an app that worked fine for one or two developers and is now too slow or must support more users. Keep all app logic intact; prefer code changes over deployment tuning; resist rewrites.
Order of preference for every fix:
- Eliminate work that isn't needed (don't compute outputs nobody is looking at; don't compute with inputs that aren't ready).
- Reuse work that repeats (shared
@reactive.calc, module-level caches). - Accelerate unavoidable work (faster data formats, polars, push-down).
- Relocate work that blocks (
@reactive.extended_task) — last resort; it buys concurrency, not raw speed.
One fact drives most Python-specific advice: every session in a process
shares one asyncio event loop. A synchronous blocking call in any reactive
function freezes every session in the process. What a slow async def
reactive blocks depends on the shiny version (check with
python -c "import shiny; print(shiny.__version__)"):
- shiny < 1.9.0: reactive functions run serially across the whole
process, so a slow
asyncreactive also freezes every session. - shiny ≥ 1.9.0: effects run concurrently, so a slow
asyncreactive holds only its own session (no input updates, no outputs until it finishes); other sessions keep running.
Either way, async/await alone never keeps the same session responsive;
only @reactive.extended_task does. And 1.9.0 changes nothing for sync code:
time.sleep, pandas, matplotlib drawing, or a sync DB call still freezes
every session on every version. Don't recommend upgrading shiny to fix a
freeze caused by sync work.
Workflow
1. Understand the complaint
Pin down what "slow" means and write it as a benchmark to beat:
- What feels slow? First page load? Every interaction? One specific action? Only when several people use it at once?
- How many concurrent users must it support? (1–5, ~20, hundreds?)
- Where does it run? Locally, Posit Connect, Posit Connect Cloud, self-hosted (uvicorn behind nginx)?
- How big is the data, where does it live, and how often does it change?
- Core or Express? (
from shiny import ...vsfrom shiny.express import ...). Express top-level code runs once per session — a common silent trap (data-loading.md).
2. Scan the source for smells — and fix them now
Read the app code (app.py, modules) and look for the classic smells. Every
smell in this table has a safe, behavior-preserving fix: apply each fix
you find immediately, before measuring. These changes fix the large majority
of slow Shiny for Python apps.
| Smell (search for) | Why it hurts | Fix |
|---|---|---|
pd.read_csv/DB queries inside server() or render functions |
Re-runs per session or per invalidation | Load once per process: module scope (Core), imported module (Express) → data-loading.md |
Data loads at top level of an Express app.py |
Top-level Express code runs once per session | Move loads into an imported module (shared.py) → data-loading.md |
| Same subsetting/aggregation repeated in several outputs | Duplicate computation on every change | Extract one shared @reactive.calc → reactive-graph.md |
Expensive @render.* with no req() guard |
Computes on empty/half-ready inputs at startup | req() at the top of the body → reactive-graph.md |
| Many heavy outputs on the landing view | All must compute before the page is usable | Move to tabs/navs — hidden outputs are suspended → rendering-ui.md |
| Identical expensive work repeated across sessions | Every user re-pays the same cost | Module-level cache (functools.lru_cache, diskcache) — there is no built-in bindCache equivalent → caching.md |
| Sliders/text inputs feeding expensive chains directly | One drag = dozens of recomputations | @reactive.event() button gating; debounce helper → reactive-graph.md |
time.sleep, sync requests, heavy pandas/DuckDB calls inline in calcs/effects/renders |
Blocks the event loop for every user in the process | @reactive.extended_task → async-tasks.md |
async def reactives added expecting a speedup |
A slow async reactive still holds its session (and, on shiny < 1.9.0, every session) | Async only for async-only APIs; ExtendedTask for non-blocking → async-tasks.md |
@render.ui used for routine value updates |
DOM rebuild + input re-binding per update | ui.update_*() → rendering-ui.md |
@render.table on large data frames |
pandas Styler → full HTML serialization | @render.data_frame with render.DataGrid |
Установить shiny-py-optimize в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл shiny-py-optimize?
Diagnose and fix performance problems in Shiny for Python apps — slow startup, sluggish interactions, blocking operations, and apps that struggle beyond a handful of concurrent users. Use when a Shiny for Python app is slow, hangs, recomputes too much, times out, or must support more users; when the user asks to "speed up", "optimize", or "make faster" a Python Shiny app; or when preparing a prototyped app for real-world traffic.
Как установить скилл shiny-py-optimize?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл shiny-py-optimize запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic