Skip to content

Latest commit

 

History

History
104 lines (73 loc) · 2.84 KB

File metadata and controls

104 lines (73 loc) · 2.84 KB

Progressive System Loading + Data Compression

Phase 0 Progressive Rendering (js/galaxy3d.js)

Problem solved: System enter was janky (all 3D assets + textures at once).

Solution: 4-phase lazy loading per planet:

T=0ms      Phase 0: Orbits + Star + Planet Spheres (flat color)
           → systemPlanetEntries built, animation starts
           → Fleets rendered immediately
           
T=50-100ms Phase 1: Planet 0 texture canvas-gen + material swap
T=100-150ms Phase 1: Planet 1 texture gen...
T=150-200ms Phase 1: Planet 2 texture gen...

T=...+10ms Phase 2: Atmosphere shells per planet
T=...+10ms Phase 3: Cloud shells per planet

Implementation:

  • _buildSystemPhase0() – Quick baseline (geometry, no textures)
  • _queueSystemRefinement() – Build task queue (50ms staggered per planet)
  • _processSystemRefinementQueue() – Async texture gen in tasks
  • Cleanup: exitSystemView() cancels pending tasks

Result: System appears in ~0ms, visually complete in ~200-500ms (staggered).


Data Compression (api/compression.php)

Problem: System API responses 50-200KB JSON. Transit time bottleneck.

Solution: 3 tiers:

Tier 1: Browser Gzip (Automatic)

  • gzip header + ob_gzhandler
  • Works: ~60-70% reduction (12KB for typical system)
  • Status: Enabled in api/galaxy.php

Tier 2: Payload Trimming (Optional, +30-40% savings)

  • Remove unused fields from response
  • ?trim=1 flag
  • Stripped fields: server_ts, deposit_*, building details, etc.
  • Enabled by default in API.galaxy() (js/api.js)

Tier 3: Binary Encoding (Phase 2)

  • MessagePack-like format: ~40% of gzipped JSON
  • Schema defined in api/compression.php
  • Not implemented yet (opt-in for future)

Usage

From JS

// Trimmed + gzipped (now default):
const payload = await API.galaxy(1, 1);

// Full response (backwards compat):
const fullPayload = await fetch('api/galaxy.php?galaxy=1&system=1').then(r => r.json());

From PHP

enable_response_gzip(); // Add to any API endpoint

// Optional trimming
$response = trim_system_payload_for_transit($payload);

Bandwidth Savings

Format Size Time (5G) Notes
Full JSON 120 KB 156 ms Baseline
+ Gzip 16 KB 21 ms Browser default
+ Trim 10 KB 13 ms Field reduction
+ Binary 4 KB 5 ms Phase 2

Current (Gzip + Trim): 91% reduction vs baseline.


Future Work

  1. Binary Format (?format=bin)

    • Implement MessagePack on server (if available)
    • JS decoder for parsing
    • Fallback to JSON
  2. Delta API (?since_ts=1234567890)

    • Only fleet/colony changes since last fetch
    • Reduces payload for live updates
  3. GraphQL Variant (POST /api/graphql)

    • Client picks exact fields needed
    • 20-30% smaller than REST trim