perf(analytics): per-event HTTP flush causes excessive network requests — add batching #68

Closed
opened 2026-05-28 01:52:11 +00:00 by funman300 · 0 comments
Owner

Problem

analytics_plugin.rs fires an HTTP request for every individual analytics event. During active gameplay, this can mean dozens of requests per minute (move made, card flipped, hint used, etc.), creating:

  • High network overhead on mobile (battery drain)
  • Potential rate-limiting from the analytics backend
  • Noticeable latency spikes if the request blocks

Affected file

solitaire_engine/src/analytics_plugin.rs

Fix

Buffer events in a Vec<AnalyticsEvent> resource and flush in batches:

  • On a timer (every 30s)
  • On game session end
  • On app background / suspend
fn flush_analytics_batch(
    mut buffer: ResMut<AnalyticsBuffer>,
    // ...
) {
    if buffer.events.is_empty() { return; }
    let batch = std::mem::take(&mut buffer.events);
    // POST batch as array
}
## Problem `analytics_plugin.rs` fires an HTTP request for every individual analytics event. During active gameplay, this can mean dozens of requests per minute (move made, card flipped, hint used, etc.), creating: - High network overhead on mobile (battery drain) - Potential rate-limiting from the analytics backend - Noticeable latency spikes if the request blocks ## Affected file `solitaire_engine/src/analytics_plugin.rs` ## Fix Buffer events in a `Vec<AnalyticsEvent>` resource and flush in batches: - On a timer (every 30s) - On game session end - On app background / suspend ```rust fn flush_analytics_batch( mut buffer: ResMut<AnalyticsBuffer>, // ... ) { if buffer.events.is_empty() { return; } let batch = std::mem::take(&mut buffer.events); // POST batch as array } ```
funman300 added the performance label 2026-05-28 01:52:11 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: funman300/Ferrous-Solitaire#68