From f8a7d674f9d183dc19fe5b38568744dddf66df24 Mon Sep 17 00:00:00 2001 From: Maurice Date: Sun, 29 Nov 2026 10:04:13 +0100 Subject: [PATCH] perf(atlas): keep the globe's geometry for the next visit Every visit read the manifest and the world file again and triangulated the countries in the worker, which showed the loading notice for about a second. The manifest and the built world meshes are now kept for the tab's lifetime, keyed by the content-hashed file name, so coming back puts the globe up at once. A page load starts empty, so a deploy's new geometry is read as before. --- .../src/components/AtlasGlobe/GlobeEngine.ts | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/client/src/components/AtlasGlobe/GlobeEngine.ts b/client/src/components/AtlasGlobe/GlobeEngine.ts index 20204f883..b40a550f4 100644 --- a/client/src/components/AtlasGlobe/GlobeEngine.ts +++ b/client/src/components/AtlasGlobe/GlobeEngine.ts @@ -93,6 +93,16 @@ const WORLD_LOD_ZOOM: Array<[string, number]> = [ ['l0', 0], ]; const MAX_EDGE: Record = { l0: 8, l1: 4, l2: 2, r0: 3, r1: 1.5 }; + +/** + * What one visit to the Atlas loaded and built, kept for the next one in this + * tab: the manifest and the built world meshes, by file name (the name carries + * the content hash). Coming back then puts the globe up at once, instead of + * reading and triangulating the world again behind a loading notice. A new + * page load starts empty, so a deploy's new geometry is read as before. + */ +let keptManifest: Promise | null = null; +const keptWorlds = new Map(); const FIRST_REGION_ID = 512; export class GlobeEngine { @@ -206,7 +216,14 @@ export class GlobeEngine { private async boot(): Promise { try { - this.manifest = (await this.fetchRetrying('manifest')) as AtlasMeshManifest; + keptManifest ??= this.fetchRetrying('manifest') as Promise; + try { + this.manifest = await keptManifest; + } catch (err) { + // A failed read is not kept: the next visit asks again. + keptManifest = null; + throw err; + } await this.loadWorld('l0'); this.revealStart = this.now(); this.opts.onReady?.(); @@ -220,8 +237,13 @@ export class GlobeEngine { if (!this.manifest || this.renderer.hasWorld(lod) || this.worldLoading.has(lod)) return; this.worldLoading.add(lod); try { - const topo = (await this.fetchRetrying(`world/${this.manifest.world[lod]}`)) as Topology; - const layer = await this.build(topo, 'countries', MAX_EDGE[lod], 0); + const file = this.manifest.world[lod]; + let layer = keptWorlds.get(file); + if (!layer) { + const topo = (await this.fetchRetrying(`world/${file}`)) as Topology; + layer = await this.build(topo, 'countries', MAX_EDGE[lod], 0); + keptWorlds.set(file, layer); + } if (!this.alive) return; this.renderer.setWorld(lod, layer); this.kick();