optimizing-streamlit-performance

Optimize Streamlit apps using caching APIs and UI fragmentation to reduce reruns.

487|128|Updated Mar 27, 2026
One-click install
npx skills add https://github.com/iusztinpaul/designing-real-world-ai-agents-workshop --skill optimizing-streamlit-performance-iusztinpaul
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: optimizing-streamlit-performance
Source: https://github.com/iusztinpaul/designing-real-world-ai-agents-workshop/tree/main/.agents/skills/developing-with-streamlit/skills/optimizing-streamlit-performance
Command: npx skills add https://github.com/iusztinpaul/designing-real-world-ai-agents-workshop --skill optimizing-streamlit-performance-iusztinpaul

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Streamlit apps can become slow due to repeated reruns, heavy data loads, and large UI trees; this Skill provides caching and UI-reduction strategies to keep apps responsive.

Core Features & Use Cases

  • Caching data loads with @st.cache_data to avoid recomputing expensive operations.
  • Caching resources like database connections with @st.cache_resource to speed up initialization and reduce latency.
  • Using UI fragments, forms, and conditional rendering to isolate reruns and keep interactive elements snappy.
  • Guidance for large data handling and pre-computation to precompute heavy work and serve results quickly.

Quick Start

Enable @st.cache_data and @st.cache_resource on heavy functions to cache results and refactor UI into fragments to minimize reruns.

Frequently Asked Questions about optimizing-streamlit-performance

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I speed up my Streamlit dashboard with caching?

Speed up Streamlit dashboards by applying @st.cache_data to expensive data loads and @st.cache_resource to initialization objects. This avoids recomputing heavy operations during UI reruns, keeping apps responsive with large datasets.

Why does my Streamlit app rerun and reload data on every widget interaction?

Streamlit apps rerun entirely on every widget interaction, triggering unnecessary data recomputations. Isolate interactive UI elements using st.fragment to prevent full script reruns and reduce latency for interactive widgets.

What is the best way to cache a database connection in Streamlit?

Cache database connections in Streamlit using @st.cache_resource. This speeds up initialization and reduces latency by persisting the connection object across reruns instead of recreating it on every interaction.

How do I optimize Streamlit UI fragments to minimize reruns?

Optimize Streamlit UI fragments by refactoring interactive elements into st.fragment decorators. This isolates UI updates, preventing the entire application from rerunning and keeping interactive widgets snappy for better user experience.

Can I use Streamlit caching for dashboards with large datasets?

Yes, Streamlit caching works for large datasets by combining @st.cache_data with pre-computation strategies. Precompute heavy work outside the main UI loop and cache the results to serve data quickly during interactive reruns.

When should I use st.fragment instead of caching in Streamlit?

Use st.fragment instead of caching when the bottleneck is UI reruns rather than data processing. Fragments isolate widget interactions to prevent full script execution, while caching targets expensive data loads and initialization tasks.