mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Load the layer displays lazily and rebase the main-chunk budget
Every layer display was imported statically from the manifest, so all of them sat in the Cesium-mode main chunk. They are re-exported from one module, src/app/layers/displays.js, which the manifest loads with one import() before the catalog is built, on every engine; rendererFor stays synchronous after that. One chunk beats per-family chunks here: every start loads every display, and split chunks compress worse. CCTV's world click gesture moves out of its display, which the app imported only for it. Tests that build layers without the application await the loads. Keyless, gzip-9: the main chunk falls from 2,113,641 to 2,066,560 bytes, below the 2,090,274 of the merge with main this branch carries. A cold Cesium start loads about 7 KB more JS in total over four requests, with the same time to a ready page. The budget's baseline moves to the new size; it had never absorbed main's own growth.
This commit is contained in:
1 parent
47d63128ff
commit
b53b6a48a7
22 files changed
+239
-114
No files matched your search
@@ -6,6 +6,7 @@ import {
|
||||
LAYER_MANIFEST,
|
||||
createLayerAvailability,
|
||||
layerAvailableOn,
|
||||
loadLayerRenderers,
|
||||
registerLayerRenderers,
|
||||
rendererFor,
|
||||
} from './renderers.js';
|
||||
@@ -118,6 +119,23 @@ test('the layers drawn through one display, and the ones that draw without one',
|
||||
});
|
||||
});
|
||||
|
||||
test('a display or an engine-specific renderer answers only after its engine loaded them', () => {
|
||||
const engine = createFakeEngine({ kind: 'navara' });
|
||||
// Nothing is loaded yet: the later tests load them.
|
||||
assert.throws(
|
||||
() => rendererFor('weather-radar', engine),
|
||||
/weather-radar on navara: its renderer is not loaded/,
|
||||
);
|
||||
assert.throws(() => rendererFor('cctv', engine), /not loaded/);
|
||||
const cesium = createFakeEngine();
|
||||
assert.throws(
|
||||
() => rendererFor('flights', cesium),
|
||||
/flights on cesium: its renderer is not loaded/,
|
||||
);
|
||||
cesium.destroy();
|
||||
engine.destroy();
|
||||
});
|
||||
|
||||
test('the layers drawn through one display get the same factory on every engine', async () => {
|
||||
const displays = {
|
||||
flights: ['flights', 'createFlightsDisplay'],
|
||||
@@ -164,11 +182,12 @@ test('the layers drawn through one display get the same factory on every engine'
|
||||
const factory = (
|
||||
await import(`../../layers/${directory}/render/display.js`)
|
||||
)[name];
|
||||
assert.equal(LAYER_MANIFEST[id].display, factory, id);
|
||||
assert.equal(await LAYER_MANIFEST[id].display(), factory, id);
|
||||
// Each display's own tests build it with its services; the aircraft
|
||||
// family needs none beyond an atlas.
|
||||
if (!['flights', 'military', 'local-adsb'].includes(id)) continue;
|
||||
for (const kind of ENGINE_KINDS) {
|
||||
await loadLayerRenderers(kind);
|
||||
const engine = createFakeEngine({ kind });
|
||||
const display = rendererFor(id, engine, { drawAtlas });
|
||||
assert.equal(display.engine, engine, `${id} on ${kind}`);
|
||||
@@ -194,17 +213,6 @@ test('a layer that draws itself has no renderer; an unknown engine none either',
|
||||
engine.destroy();
|
||||
});
|
||||
|
||||
test('an engine-specific renderer answers only after its engine loaded them', () => {
|
||||
const engine = createFakeEngine({ kind: 'navara' });
|
||||
// This test file never loads Navara's renderers.
|
||||
assert.throws(
|
||||
() => rendererFor('weather-radar', engine),
|
||||
/weather-radar on navara: its renderer is not loaded/,
|
||||
);
|
||||
assert.throws(() => rendererFor('cctv', engine), /not loaded/);
|
||||
engine.destroy();
|
||||
});
|
||||
|
||||
test('a test engine of its own kind brings its renderers', () => {
|
||||
const made = [];
|
||||
registerLayerRenderers('renderers-test', {
|
||||
|
||||
Reference in new issue
Block a user