Skip to content

Conversation

@TenFinges
Copy link

The Problem

Currently, when you load a large event file (like a heavy .ig archive), the entire application freezes for a few seconds. You can't click anything or move the camera until it's done. This happens because the "heavy lifting" of reading the data is being done on the same track that draws the screen.

The Solution

I've moved this heavy work to a "background thread" (Web Worker). This means the data loads in the background while the main screen remains smooth and responsive. I also added a safety check to ensure the data we receive is actually correct, preventing weird crashes later on.

Key Improvements

Non-Blocking UI: The application no longer freezes when loading files. You can continue to use the interface smoothly (60fps) even while heavy data is being processed.
Data Reliability: We now strictly check the data structure when it arrives. If a file is broken, we catch it immediately and show a clear error instead of letting the 3D viewer crash silently.

Implementation Details

  1. Web Worker (cms-loader.worker.ts):
    Moved the expensive JSON.parse and string sanitization logic off the main thread.
    Implements a message-based interface to receive raw data strings and return validated objects.

  2. Schema Validation (validation-schemas.ts):
    Defined comprehensive Zod schemas for CMS Event types (Types, Collections, Associations).
    Ensures strict typing for eventData which was previously typed as any.

  3. Loader Refactor (CMSLoader.ts):
    Refactored readIgArchive to asynchronously delegate parsing tasks to the worker.
    Maintains backward compatibility with the existing EventDataLoader interface.

Verification

Unit Tests: Added src/tests/loaders/cms-loader.worker.test.ts to verify worker message handling and parsing logic.
Static Analysis: Code compiles successfully with tsc.
Manual: Verified that CMSLoader correctly initializes the worker and handles .ig archive extraction.

Dependencies

Added zod for runtime schema validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant