Skip to content

feat: offload JiveXML/JSON parsing to Web Worker to prevent UI freeze#856

Open
Shivansh1205 wants to merge 2 commits intoHSF:mainfrom
Shivansh1205:feat/web-worker-event-parsing
Open

feat: offload JiveXML/JSON parsing to Web Worker to prevent UI freeze#856
Shivansh1205 wants to merge 2 commits intoHSF:mainfrom
Shivansh1205:feat/web-worker-event-parsing

Conversation

@Shivansh1205
Copy link
Copy Markdown
Contributor

Problem

JiveXMLLoader.getEventData() runs DOMParser + full XML data extraction synchronously on the main thread. For large ATLAS events with dense track collections, this causes multi-second UI freezes affecting every experiment (ATLAS, CMS, LHCb, TrackML).

Solution — Phase 1: Worker-based parsing

The key insight: parsing + data extraction (expensive) can run in a worker, while Three.js object creation (needs WebGL context) stays on the main thread — but by that point the data is already structured and fast to process.

Changes

  • src/workers/event-data-parser.worker.ts — Web Worker that runs DOMParser and all JiveXML data extraction off the main thread, returning plain serialisable objects (no DOM nodes cross the worker boundary). Also handles JSON.parse for future use.

  • src/workers/event-data-parser.ts — Promise-based wrapper with automatic synchronous fallback when Worker is unavailable (SSR, older browsers).

  • src/loaders/jivexml-loader.tsgetEventData() is now async. Delegates XML parsing to the worker; private build*() methods reconstruct the event data from the plain worker result.

  • src/event-display.tsbuildEventDataFromJSON() and loadEvent() are now async.

Considerations addressed

  • Workers cannot access DOM/Three.js — only pure data parsing is offloaded
  • Fallback to synchronous path if Workers unavailable
  • No transferable objects needed (string input, plain object output)
  • Phase 2 (chunked progress reporting) can be layered on top of this worker infrastructure

@EdwardMoyse
Copy link
Copy Markdown
Collaborator

This is a bit hard to review because GitHub seems to think that you are adding jivexml-loader.ts and event-display.ts i.e. I cannot easily see the lines you have changed. I'm not sure why. :-/

I will have to look at this more carefully this evening.

@sponce
Copy link
Copy Markdown
Collaborator

sponce commented Mar 30, 2026

This is due to the fact that the new files is not in the right place in the hierarchy. Instead of being in path phoenix/packages/phoenix-event-display/src/loaders/jivexml-loader.ts, where '/' separates the directories, it's in phoenix\/packages\/phoenix-event-display\/src/loaders\/jivexml-loader.ts, meaning there is a directory called phoenix/packages/phoenix-event-display/src t the top level. @Shivansh1205 can you fix this ?

@Shivansh1205
Copy link
Copy Markdown
Contributor Author

@sponce i will try doing it by this evening

@Shivansh1205 Shivansh1205 force-pushed the feat/web-worker-event-parsing branch from be2adc8 to 279e8d0 Compare March 31, 2026 09:37
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.

3 participants