Files
Echoion/VOIDLIBRARY_TODO.md
faumaray 818d391022 Update
Signed-off-by: faumaray <faumaray@gmail.com>
2026-07-15 19:50:44 +03:00

7.7 KiB
Raw Permalink Blame History

VoidLibrary — work needed to fully migrate Echoion (+ upgrade ideas)

STATUS (migration complete)

Almost everything below has now landed. Echoion uses Void for Json, Logging, Process, Retry, Configuration, EventBus (async), ThreadPool, Cache, Resilience, BufferPool, Result, and glaze is fully removed. The blockers A1–A6 were all implemented in VoidLibrary as universal primitives and consumed by Echoion:

  • A1 done — Void/Data/Reflect.hpp now reflects chrono::duration, time_point, variant, array, non-string map. TrackInfo/RPC/state serialize via reflection; glaze gone.
  • A2 done — Void::EventBus gained Mode::Async; Echoion's bus delegates to it.
  • A3 done — Void::Concurrency::ThreadPool gained bounded queue + try_submit
    • rejection stats (Echoion's ConnectionPool deleted).
  • A4 done — Void::Containers::Cache (TTL + policy + stats) added; LruCache deleted.
  • A5 done — Void::Resilience (TokenBucket, KeyedRateLimiter, CircuitBreaker, ResourceMonitor); Echoion's RateLimiter/CircuitBreaker/ ResourceMonitor deleted.
  • A6 done — Void::BufferPool::BufferPool<T> added; AudioBufferPool wraps it; bespoke MemoryPool deleted. New Void::System metrics (process_memory/cpu) added.

Remaining: none from the migration list. CoreLoader now uses Void::Plugin::PluginManager with pinned handles, host-side interface validation, explicit activation readiness, state checkpoint/restore, and rollback to a reactivated previous Core. Successful and rejected replacement paths are covered by an end-to-end reload test.

The historical analysis below is retained for reference.


A. Blockers — feature parity VoidLibrary must add

A1. JSON reflection: native chrono / variant / map / array support — HIGHEST IMPACT

Problem. Void/Data/Reflect.hpp only (de)serializes arithmetic, enum, string, optional, vector, string-keyed map, and aggregates. It cannot handle std::chrono::duration / time_point, std::variant, std::map with non-string keys, or std::array. A single such member makes a whole struct non-reflectable.

Echoion impact. Forced hand-written to_json/from_json for TrackInfo, and *Json mirror structs for config. It still blocks HotReloadState (its BotConfig/QueueEntry/PlaybackState carry chrono) and RPC (RpcRequest/ RpcResponse/RpcNotification carry time_point).

Ask. Built-in reflection handling for:

  • std::chrono::duration<Rep,Period> → integer count (Meta already exposes is_duration_v), and time_point → epoch millis — encoding ideally selectable via a field attribute ([[= Json::ChronoAs{Millis}]]).
  • std::variant (tagged, or first-that-parses).
  • std::map<K,V> for non-string keys.
  • std::array<T,N>.

Payoff. Removes essentially all remaining manual serializers and directly unblocks the HotReloadState + RPC migrations. Do this first.

A2. EventBus: async / queued dispatch mode

Problem. Void::EventBus::publish() invokes handlers inline (synchronous). Echoion's bus is async (background thread) because its handlers do network broadcasts (rpcServer_->broadcastEvent) and SQLite writes (database_->recordPlayback). Sync dispatch would run that I/O on the publisher's thread (the playback path) → blocking and lock-ordering deadlock risk.

Ask. An async dispatch mode (worker thread or Void::Concurrency::ThreadPool backed), e.g. EventBus(Mode::Async) with drain()/flush(), keeping sync as the default. Optional ordered delivery + coalescing.

Payoff. Echoion drops its custom EventBus + GlobalEventBus.

A3. ThreadPool: bounded queue + backpressure / rejection

Problem. Void::Concurrency::ThreadPool::submit() is unbounded. Echoion's ConnectionPool exists specifically for admission control: a bounded queue, try_submit() returning false when full (prevents resource exhaustion under RPC load), plus active / queued / processed / rejected stats.

Ask. A bounded-capacity option + try_submit() -> bool (or expected) + basic counters (pending, active, processed, rejected).

Payoff. Echoion drops ConnectionPool.

A4. Cache: TTL + eviction policies + stats

Problem. Void::Containers::LruCache is capacity-only. Echoion's LruCache has per-entry TTL expiry, selectable eviction policy (LRU/LFU/FIFO/TTL), and stats (hits/misses/evictions/inserts/hitRate/memoryUsage) — used for audio and metadata caching where TTL matters.

Ask. A richer cache (or options on LruCache): per-entry TTL, pluggable eviction policy, hit/miss/eviction counters, optional size/memory accounting.

Payoff. Echoion drops its Cache.

A5. Resilience primitives — net-new Void::Resilience module

None of these exist in Void today; all are standard, broadly useful service primitives:

  • RateLimiter — token bucket, per-key, configurable rate + burst, stale-entry cleanup. (echoion RateLimiter)
  • CircuitBreaker — CLOSED / OPEN / HALF_OPEN, failure threshold, reset timeout, stats. (echoion CircuitBreaker)
  • ResourceMonitor — memory / CPU / queue-depth sampling with threshold + pressure callbacks. (echoion ResourceMonitor)

A6. MemoryPool: typed audio-buffer / arena pool

Problem. Void::Containers::Pool is a slab object pool (acquire() → unique_ptr<T>). Echoion's MemoryPool pools reusable int16 audio sample buffers (grow-on-demand, zero-copy views) on the decode→playback hot path.

Ask. A buffer/arena pool variant (pooled contiguous T buffers with reuse + high-water stats), or confirm Pool<std::vector<int16_t>> is an acceptable fit.


B. Already replaceable — no VoidLibrary change needed (Echoion-side work only)

  • Plugin loader → Void::Plugin (done). Loader::reload() + Manager (FileWatcher, RCU-pinned handles so "work never stops for a reload") + the v2 serialize_state/deserialize_state C-ABI protocol already cover — and improve on — Echoion's CoreLoader/dylib/FileWatcher. The "defer reload until the current track finishes" behaviour is a policy Echoion can layer on Manager.
  • RPC JSON and HotReloadState are blocked only by A1 (plus the Desktop client moving in lockstep for the RPC wire format).

C. Upgrade ideas (general VoidLibrary improvements)

  • Json: streaming/SAX parser + incremental serialize for large docs (yt-dlp -J playlist output is often MBs); JSON Pointer / path query (get_as<T>(path)); parse integers without a double round-trip; a from_json that collects all field errors, not just the first.
  • Json reflection: read-side key aliases, per-field defaults, and the chrono encoding attribute from A1.
  • Process: async/streaming variant (incremental stdout for progress), env-var and working-directory control, and a kill/signal handle for long-running children.
  • Retry: jitter (full / decorrelated) on backoff; an overall deadline / retry budget.
  • Logging: structured (JSON/logfmt) sink; per-module level sourced from Configuration; a sampling / rate-limited sink; optional console level-split (info→stdout, error→stderr).
  • Configuration: typed get_as<T> with chrono + byte-size units (Echoion config uses "1GB", "30000ms").
  • Service: scoped / child registries; ordered startup with declared dependency edges.

Priority (by Echoion unblock value)

  1. A1 (JSON chrono/variant) — unblocks RPC + HotReloadState and deletes the manual serializers. Biggest single win.
  2. A2 (async EventBus) — removes an entire subsystem.
  3. A3 / A4 (ThreadPool backpressure, Cache TTL+stats).
  4. A5 (resilience module).
  5. A6 (audio buffer pool).