1.7 KiB
1.7 KiB
I will optimize the loading process by implementing a Multi-Threaded Worker Loader. This involves creating a pool of Web Workers to fetch assets (JavaScript, Audio, Images, Views) in parallel, offloading the network initiation and handling from the main thread.
Plan:
-
Create
public/src/js/loader-worker.js:- This worker will handle
fetchrequests for different resource types (text,blob,arraybuffer). - It will transfer the data back to the main thread (using zero-copy transfer for
ArrayBuffer).
- This worker will handle
-
Modify
public/src/js/loader.js:- Initialize Worker Pool: Create a pool of workers (defaulting to 4) in the
Loaderclass. - Implement
workerFetch(url, type): A method to distribute fetch tasks to the worker pool. - Override
ajax(url, ...): Intercept requests for static assets (src/,assets/, etc.) and route them throughworkerFetch. Keep API calls (api/) on the main thread to ensure session stability. - Update
loadScript(url): Change it to fetch the script content viaworkerFetchand inject it using a<script>tag with inline content. This ensures JS files are also loaded via the "multi-process" mechanism. - Update
loadSoundandRemoteFilelogic: SinceRemoteFileusesloader.ajax, routingajaxto workers will automatically parallelize audio loading.
- Initialize Worker Pool: Create a pool of workers (defaulting to 4) in the
Technical Details:
- Concurrency: 4 Workers will be used to maximize throughput without overloading the browser's connection limit per domain.
- Resource Types:
- JS/Views: Fetched as
text. - Images: Fetched as
blob->URL.createObjectURL. - Audio: Fetched as
arraybuffer->AudioContext.decodeAudioData.
- JS/Views: Fetched as