<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Latency on 每日拍拍</title>
    <link>https://dailypypy.org/tags/latency/</link>
    <description>Recent content in Latency on 每日拍拍</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>zh-tw</language>
    <copyright>© 2026 每日拍拍</copyright>
    <lastBuildDate>Wed, 30 Sep 2026 10:41:00 +0800</lastBuildDate><atom:link href="https://dailypypy.org/tags/latency/index.xml" rel="self" type="application/rss+xml" />
    <follow_challenge>
      <feedId>155076163427069952</feedId>
      <userId>154825760438254592</userId>
    </follow_challenge>
    
    
    <item>
      <title>Streamlit 效能診斷：Rerun、Cache Hit、記憶體與 Latency Profiling</title>
      <link>https://dailypypy.org/learn/streamlit-performance-profiling/</link>
      <pubDate>Wed, 30 Sep 2026 10:41:00 +0800</pubDate>
      
      <guid>https://dailypypy.org/learn/streamlit-performance-profiling/</guid>
      <description>&lt;!---
1440x768
prompt: masterpiece, best quality, highres, clean anime illustration, japanese anime style, soft shading, flat color design, 1girl, black hair, green eyes, white off-shoulder shirt, black short skirt, from above, three-quarter view, crouching beside three translucent blank gauge panels while tracing a soft glowing line with one finger, alert analytical smile, looking up at viewer, pastel aqua and pale lilac background, subtle stopwatch circles and memory-block shapes without symbols, logos, markings, numbers, letters, or text, neat composition, detailed eyes, cute and smart vibe, minimal background, polished illustration, no text
negative prompt: worst quality, bad eye, bad hand, extra limbs, manga, multiple views, monochrome, text, signature
dedup note: This is a measurement-specific follow-up to ../python-streamlit-advanced/, ../streamlit-fragments-dialogs/, ../streamlit-apptest-pytest/, and ../python-profiling/. Those articles teach cache and Session State usage, fragment rerun boundaries, functional AppTest checks, or general cProfile/line_profiler. This article instead defines Streamlit latency budgets, instruments complete reruns and app stages, runs controlled cold/warm cache experiments, tracks RSS versus Python heap, and turns AppTest timings into regression evidence.
source check: Reviewed against the current official Streamlit execution-flow, st.cache_data, st.cache_resource, and AppTest documentation on 2026-09-30. The examples use public APIs and treat AppTest as server-side regression evidence, not browser end-to-end latency.
---&gt;
&lt;p&gt;





&lt;figure&gt;
    &lt;img class=&#34;my-0 rounded-md&#34; loading=&#34;lazy&#34; alt=&#34;featured&#34; src=&#34;./featured.png&#34; /&gt;

  
&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;Streamlit App 變慢時，最危險的一句話是：「應該是圖表太多吧。」&lt;/p&gt;
&lt;p&gt;也可能是每次 widget 互動都重讀檔案、cache key 不斷改變、某個 API 偶爾卡住，或同一份 DataFrame 被複製到記憶體好幾次。&lt;/p&gt;
&lt;p&gt;如果沒有量測，優化就只是在猜。&lt;/p&gt;
&lt;p&gt;這篇拍拍君不再重教 &lt;code&gt;st.cache_data&lt;/code&gt; 怎麼寫，也不把一般 Python profiler 全搬過來。我們要建立一套 Streamlit 專用的診斷流程：&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;先定義冷啟動與暖 rerun 的 latency budget；&lt;/li&gt;
&lt;li&gt;量測整輪 rerun，以及 load、transform、render 各階段；&lt;/li&gt;
&lt;li&gt;用受控實驗分辨 cache hit、miss 與 key 爆炸；&lt;/li&gt;
&lt;li&gt;同時觀察 RSS 和 Python heap，不被單一數字騙走；&lt;/li&gt;
&lt;li&gt;用 AppTest 留下可重複比較的 server-side benchmark。&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;如果你想先補 Streamlit 的 rerun 與 cache 基礎，請看 &lt;a href=&#34;../python-streamlit-advanced/&#34;&gt;Streamlit 進階篇&lt;/a&gt;；想縮小 rerun 範圍，則接著看 &lt;a href=&#34;../streamlit-fragments-dialogs/&#34;&gt;Fragments + Dialogs&lt;/a&gt;。&lt;/p&gt;</description>
      <media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://dailypypy.org/learn/streamlit-performance-profiling/featured.png" />
    </item>
    
  </channel>
</rss>
