<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abdullah Taş</title>
    <description>The latest articles on DEV Community by Abdullah Taş (@abdullahtas).</description>
    <link>https://dev.to/abdullahtas</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3842192%2Fb4f195f2-d8cb-4cd8-929f-54e969e9f5d7.png</url>
      <title>DEV Community: Abdullah Taş</title>
      <link>https://dev.to/abdullahtas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/abdullahtas"/>
    <language>en</language>
    <item>
      <title>How I Eliminated Video Jank in Flutter Feeds — Instance Reuse Instead of Dispose/Create</title>
      <dc:creator>Abdullah Taş</dc:creator>
      <pubDate>Tue, 24 Mar 2026 20:50:59 +0000</pubDate>
      <link>https://dev.to/abdullahtas/how-i-eliminated-video-jank-in-flutter-feeds-instance-reuse-instead-of-disposecreate-5f6a</link>
      <guid>https://dev.to/abdullahtas/how-i-eliminated-video-jank-in-flutter-feeds-instance-reuse-instead-of-disposecreate-5f6a</guid>
      <description>&lt;p&gt;Every Flutter developer who's built a video feed has hit the same wall. You scroll through 20 videos on a Redmi Note 8 Pro, and by video 15, frames are dropping, the phone is warm, and by video 30, you're getting OOM crashes on budget devices.&lt;/p&gt;

&lt;p&gt;The root cause isn't Flutter. It's the standard approach to video lifecycle.&lt;/p&gt;

&lt;p&gt;The Problem: Dispose/Create on Every Scroll&lt;/p&gt;

&lt;p&gt;Here's what most video feed implementations do:&lt;/p&gt;

&lt;p&gt;User scrolls from video 4 to video 5&lt;br&gt;
→ controller_4.dispose()     // tears down decoder pipeline, releases texture&lt;br&gt;
→ controller_5 = VideoPlayerController.network(url)  // allocates new decoder&lt;br&gt;
→ controller_5.initialize()  // GPU texture allocation, ~15-30ms&lt;br&gt;
→ controller_5.play()&lt;/p&gt;

&lt;p&gt;Each cycle triggers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Decoder teardown&lt;/strong&gt;: The hardware decoder pipeline is torn down and rebuilt&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Texture deallocation/reallocation&lt;/strong&gt;: GPU memory freed, then re-acquired&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GC pressure&lt;/strong&gt;: Dart's garbage collector runs to clean up the old controller&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Jank spike&lt;/strong&gt;: 15-30ms pause visible as a frame drop during scroll&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On 100 scrolls, that's 100 allocation cycles. The jank compounds — GC runs become longer as heap fragments, device temperature rises reducing clock speeds, and available memory shrinks.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Solution: Never Dispose During Scroll
&lt;/h2&gt;

&lt;p&gt;What if the players just... never went away?&lt;/p&gt;

&lt;p&gt;That's the core idea behind &lt;code&gt;video_pool&lt;/code&gt;. Create N player instances at startup (typically 3), and &lt;strong&gt;reuse them&lt;/strong&gt; by swapping the video source:&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Pool Init:   Create Player-0, Player-1, Player-2&lt;br&gt;
Scroll 1→2:  Player-0 keeps video 1 (pause), Player-1 plays video 2&lt;br&gt;
Scroll 2→3:  Player-0.swapSource(video 4), Player-2 plays video 3&lt;br&gt;
Scroll 3→4:  Player-1.swapSource(video 5), Player-0 plays video 4&lt;br&gt;
...&lt;br&gt;
Result: 3 players handle infinite scroll. Zero GC pressure.&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;swapSource()&lt;/code&gt; replaces the media URI without destroying the decoder pipeline or texture surface. The player stays allocated in GPU memory — only the bitstream changes.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Architecture
&lt;/h2&gt;

&lt;p&gt;The pool doesn't just reuse players. It's a full orchestration engine:&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;User scrolls → VisibilityTracker (intersection ratios)&lt;br&gt;
  → VideoPool.onVisibilityChanged(primary: 5, ratios: {...})&lt;br&gt;
    → LifecycleOrchestrator.reconcile()&lt;br&gt;
      → queries DeviceMonitor (thermal + memory state)&lt;br&gt;
      → computes effective limits&lt;br&gt;
      → produces ReconciliationPlan&lt;br&gt;
    → VideoPool executes: release → preload → play → pause&lt;br&gt;
*&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Key design decisions:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Reconciliation plans, not direct mutation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The orchestrator never touches player state directly. It returns an immutable plan:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ReconciliationPlan(&lt;br&gt;
  toRelease: {2},      // return to idle pool&lt;br&gt;
  toPreload: {6},      // swap source for upcoming video&lt;br&gt;
  toPlay:    {5},      // play (instant if preloaded)&lt;br&gt;
  toPause:   {4},      // keep decoder, stop playback&lt;br&gt;
)&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The pool executes in strict order: release → preload → play → pause. This prevents race conditions and makes the behavior deterministic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Device adaptation via native monitoring&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Native iOS/Android code (Swift/Kotlin) streams thermal state and memory pressure to Dart every 2 seconds:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Condition&lt;/th&gt;
&lt;th&gt;Pool Response&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Thermal nominal&lt;/td&gt;
&lt;td&gt;Full capacity (3 players)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Thermal serious&lt;/td&gt;
&lt;td&gt;Reduced to 2 players, preloading disabled&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Thermal critical&lt;/td&gt;
&lt;td&gt;1 player only&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Memory terminal&lt;/td&gt;
&lt;td&gt;Emergency flush — dispose all non-playing players&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This happens automatically. No configuration needed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Disk pre-fetching in Isolate&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A separate Dart Isolate downloads the first 2MB of upcoming videos to a 500MB LRU disk cache. When the user scrolls to a preloaded video, playback starts from the local file — near-instant first frame.&lt;/p&gt;
&lt;h2&gt;
  
  
  Usage
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;VideoPoolScope(&lt;br&gt;
  config: const VideoPoolConfig(&lt;br&gt;
    maxConcurrent: 3,&lt;br&gt;
    preloadCount: 1,&lt;br&gt;
  ),&lt;br&gt;
  adapterFactory: (_) =&amp;gt; MediaKitAdapter(),&lt;br&gt;
  sourceResolver: (index) =&amp;gt; videos[index],&lt;br&gt;
  child: VideoFeedView(sources: videos),&lt;br&gt;
)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That's a full TikTok-style feed. The &lt;code&gt;VideoFeedView&lt;/code&gt; handles &lt;code&gt;PageView&lt;/code&gt; snapping, visibility tracking, and lifecycle callbacks internally.&lt;/p&gt;

&lt;p&gt;For Instagram-style mixed feeds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight dart"&gt;&lt;code&gt;&lt;span class="n"&gt;VideoPoolScope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nl"&gt;config:&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;VideoPoolConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;maxConcurrent:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;preloadCount:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nl"&gt;adapterFactory:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;MediaKitAdapter&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="nl"&gt;sourceResolver:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;getVideoSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nl"&gt;child:&lt;/span&gt; &lt;span class="n"&gt;VideoListView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nl"&gt;itemCount:&lt;/span&gt; &lt;span class="n"&gt;feedItems&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;itemBuilder:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;feedItems&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;isVideo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;VideoCard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nl"&gt;index:&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kn"&gt;source&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;feedItems&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;source&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;TextPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;feedItems&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What's in v0.3.1
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Event-sourced observability&lt;/strong&gt;: All pool operations emit typed events (&lt;code&gt;SwapEvent&lt;/code&gt;, &lt;code&gt;ThrottleEvent&lt;/code&gt;, &lt;code&gt;CacheEvent&lt;/code&gt;, etc.) via a stream&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bandwidth intelligence&lt;/strong&gt;: EMA-based bandwidth estimation adjusts preload behavior based on network speed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Predictive scroll engine&lt;/strong&gt;: Uses Flutter's scroll physics to predict where the user will stop, pre-loading that video&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cooperative multi-pool&lt;/strong&gt;: Share hardware decoder budget across multiple pool instances (e.g., Feed tab + Discover tab)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;227 unit tests&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Try It
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;dependencies:&lt;br&gt;
  video_pool: ^0.3.1&lt;br&gt;
  media_kit: ^1.1.11&lt;br&gt;
  media_kit_video: ^1.2.5&lt;br&gt;
  media_kit_libs_video: ^1.0.5&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;pub.dev&lt;/strong&gt;: &lt;a href="https://pub.dev/packages/video_pool" rel="noopener noreferrer"&gt;video_pool&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GitHub&lt;/strong&gt;: &lt;a href="https://github.com/abdullahtas0/video-pool" rel="noopener noreferrer"&gt;abdullahtas0/video-pool&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;License&lt;/strong&gt;: MIT&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I'd love feedback — especially on API design, default values, and what features you'd need before using this in production. Open an issue or comment here.&lt;/p&gt;

</description>
      <category>dart</category>
      <category>flutter</category>
      <category>android</category>
      <category>swift</category>
    </item>
  </channel>
</rss>
