Skip to content

Reuse immutable level data on reload - #1012

Open
Solessfir wants to merge 1 commit into
Try:masterfrom
Solessfir:level-cache
Open

Solessfir wants to merge 1 commit into
Try:masterfrom
Solessfir:level-cache

Conversation

@Solessfir

@Solessfir Solessfir commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Cache the current level's parsed ZEN descriptors, prepared visual mesh and terrain collision data across reloads. Each load still creates a fresh world, renderer, collision bodies, NPCs and script VM, then restores the save's mutable state.

Only one level is retained. Changing levels or mounting archives invalidates it; the key also includes the game version and software ray-tracing mode. ENGINE.worldCacheMiB defaults to 512 and accepts 0 to disable retention. This is an estimated retention budget, not a hard RAM limit. The original source mesh is still released after preparing its visual and collision representations.

Measurements

Release builds compared with unchanged upstream d2a94b4a, using the same Gothic II save and settings. Timings cover the complete load request through session finalization and renderer setup, not only static mesh preparation.

Cached reload Before After Saved
Galaxy S24 median, 15 reloads each 1,198 ms 757 ms 441 ms, 36.8%
Galaxy S24 total, 15 reloads each 20.71 s 11.74 s 8.97 s, 43.3%
Windows median, 5 reloads each 924 ms 532 ms 392 ms, 42.5%

On Android, three fresh processes per version each performed one initial load and five reloads, in baseline/cache/cache/baseline/cache/baseline order. Reload ranges were 1,154-1,949 ms before and 710-1,136 ms after. Battery temperature rose from about 34 to 38 C during testing, so these are measured results, not a device-independent guarantee. Median initial loads were 3.85 s before and 3.56 s after, measured separately and excluded from the reload totals. Windows used an i9-14900HX with Vulkan, ray tracing and mesh shading disabled; initial loads were 2.37 s before and 2.30 s after. An earlier desktop run during concurrent compilation was excluded.

The tested Android level retained approximately 138 MiB of estimated cache data. This trades RAM for faster reloads; GPU resources and live-world reconstruction remain uncached.

Checks

  • Shared collision-data lifetime and independent per-world bodies: 11 focused checks passed.
  • A real Gothic II NewWorld -> OldWorld -> NewWorld transition preserved modified NPC strength/inventory, chest contents and a trigger's disabled state. Six subsequent loads, including five cached reloads, restored the same mutations. The final save and nested visited-world archive passed CRC checks.
  • With retention disabled, the phone completed six loads: 3.31 s initial load and 1.21 s median reload.

@Try

Try commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Hi, @Solessfir !

This PR is a mess. There is no point of doing any from of data roundtrip thru Resources to begin with. If you intent to reuse land-mesh - just move it (std::move) from previous game-session ahead of loading and forward into loading procedure.

@Solessfir

Copy link
Copy Markdown
Contributor Author

Will do it this way, thx!

@Solessfir

Solessfir commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Reworked as suggested: no roundtrip through Resources anymore. On save load, the land collision data and the uploaded landscape mesh are moved out of the previous session before it is destroyed and forwarded into World, which reuses them only for the same level and drops them otherwise before parsing.

Reload median, same save, 3 processes x 5 reloads per mode in alternating order:

Before After
Windows, Release 833 ms 538 ms
Galaxy S24, Release APK 1,088 ms 795 ms

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.

2 participants