Files
tuliprox/shared/src/model/config/epg.rs
T
euzu 8cc9283a31 Playlist Update Optimization: Reduced Memory Usage
An optimization has been introduced to reduce memory consumption during playlist updates.

Overview
Previously, provider playlists were fully loaded into memory during the update process. For large playlists (e.g. hundreds of thousands of entries or multiple providers), this could result in significant RAM usage.
With the new implementation, it is now possible to optionally read provider playlists directly from disk instead of keeping them entirely in memory.

How It Works
 - users can configure whether:
     - Provider playlists are loaded into memory (previous behavior), or
     - Provider playlists are streamed to/from disk to minimize RAM usage.

Processing remains sequential and batch-based, ensuring identical functional behavior.
This approach significantly lowers peak memory usage, especially on systems with limited resources.

Benefits

- Reduced peak RAM consumption during playlist updates
- Better scalability for large playlists and multiple providers
- Full backward compatibility

Trade-offs / Drawbacks

 - Increased processing time due to reduced in-memory caching
 - Higher disk I/O usage, especially for large or fragmented playlists
 - Performance depends more strongly on disk speed (Nvme SSD, HDD)
 - Slightly increased CPU overhead due to repeated parsing and deserialization
 - Not optimal for environments where fast updates are more important than memory usage

Recommendation

 - Use in-memory mode for systems with sufficient RAM and a focus on update speed
 - Use disk-based mode for large playlists, multiple providers, or memory-constrained environments
2026-01-08 15:11:12 +01:00

75 lines
2.5 KiB
Rust

use crate::{info_err_res};
use crate::error::{TuliproxError};
use crate::model::EpgSmartMatchConfigDto;
use crate::utils::{is_false};
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq)]
#[serde(deny_unknown_fields)]
pub struct EpgSourceDto {
pub url: String,
#[serde(default)]
pub priority: i16,
#[serde(default, skip_serializing_if = "is_false")]
pub logo_override: bool,
}
impl EpgSourceDto {
pub fn prepare(&mut self) {
self.url = self.url.trim().to_string();
}
pub fn is_valid(&self) -> bool {
!self.url.is_empty()
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, PartialEq, Default)]
#[serde(deny_unknown_fields)]
pub struct EpgConfigDto {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub sources: Option<Vec<EpgSourceDto>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub smart_match: Option<EpgSmartMatchConfigDto>,
#[serde(skip)]
pub t_sources: Vec<EpgSourceDto>,
}
impl EpgConfigDto {
pub fn prepare<F>(&mut self, create_auto_url: F, include_computed: bool) -> Result<(), TuliproxError>
where
F: Fn() -> Result<String, String>,
{
if include_computed {
self.t_sources = Vec::new();
if let Some(epg_sources) = self.sources.as_mut() {
for epg_source in epg_sources {
epg_source.prepare();
if epg_source.is_valid() {
if include_computed && epg_source.url.eq_ignore_ascii_case("auto") {
let auto_url = create_auto_url();
match auto_url {
Ok(provider_url) => {
self.t_sources.push(EpgSourceDto {
url: provider_url,
priority: epg_source.priority,
logo_override: epg_source.logo_override,
});
}
Err(err) => return info_err_res!("{err}")
}
} else {
self.t_sources.push(epg_source.clone());
}
}
}
}
if let Some(smart_match) = self.smart_match.as_mut() {
smart_match.prepare()?;
}
}
Ok(())
}
}