optimizing-streamlit-performance

Optimize Streamlit apps with caching, fragments, and rerun reduction.

Updated Feb 19, 2026
One-click install
npx skills add https://github.com/guihousun/NTL-GPT-Clone --skill optimizing-streamlit-performance-guihousun
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: optimizing-streamlit-performance
Source: https://github.com/guihousun/NTL-GPT-Clone/tree/main/skills/developing-with-streamlit/skills/optimizing-streamlit-performance
Command: npx skills add https://github.com/guihousun/NTL-GPT-Clone --skill optimizing-streamlit-performance-guihousun

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Streamlit apps often re-run entire scripts on every interaction, causing slow responses and wasted compute. This Skill provides guidelines to optimize performance through caching, fragmenting reruns, and smart UI decisions.

Core Features & Use Cases

  • Caching strategies: @st.cache_data, @st.cache_resource with TTL and max_entries to control recomputation.
  • Fragmented reruns: Use @st.fragment to isolate heavy UI pieces and run costlier tasks only when needed.
  • Large data handling: Techniques for loading large datasets efficiently, including sample-based loading and resource caching.

Quick Start

Enable caching on data-loading functions and refactor heavy widgets to reduce reruns in your Streamlit app.

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 Streamlit apps that re-run slowly on every interaction?

Speed up Streamlit apps by applying caching decorators like @st.cache_data and @st.cache_resource to prevent unnecessary recomputation. You can also isolate heavy UI components using @st.fragment to avoid full script reruns.

What is the difference between @st.cache_data and @st.cache_resource in Streamlit?

@st.cache_data is used for caching computation results like loaded dataframes, while @st.cache_resource caches global resources like database connections. Both support TTL and max_entries to control when cached values expire and limit memory usage.

How do I use Streamlit fragments to isolate heavy widgets and reduce reruns?

Use @st.fragment to isolate heavy UI pieces so they execute independently without triggering a full Streamlit script rerun. This allows costlier tasks to run only when needed within that specific fragment boundary.

What is the best way to handle large datasets in Streamlit without freezing the UI?

Handle large datasets in Streamlit by using sample-based loading and @st.cache_resource to manage memory efficiently. Combining these techniques with smart widget choices prevents UI freezing during frequent interactive updates.

When should I not use caching for interactive dashboards in Streamlit?

Avoid caching in Streamlit dashboards when displaying real-time data that must update instantly on every interaction. If your TTL is too high or max_entries limits are restrictive, users will see stale data instead of live updates.

Does Streamlit caching work with forms and widgets to prevent unnecessary reruns?

Yes, Streamlit caching works with forms by using st.form to batch widget inputs and prevent reruns until submission. Combining st.form with @st.cache_data minimizes redundant computations during frequent dashboard interactions.