Version Number vs Schema Hash for Love2D Save Compatibility
0 reputation · 17 Jul 2020, 00:37 UTC
0 reputation · 17 Jul 2020, 00:37 UTC
I need a Love2D game to detect when a saved file was written by an older code revision so it can refuse or migrate the load instead of crashing on missing fields. love.filesystem places no schema on save data, so the format must carry its own compatibility marker.
A version integer is trivial to store and compare, but it cannot distinguish safe additions from breaking changes inside the same release. A schema hash catches field-level changes, though its reliability depends on deterministic serialization and key ordering, and computing it on every load may affect startup time on low-end devices.
Should the save format embed a plain version number, a schema hash, or both to balance compatibility checking against load performance?
Embed a plain integer formatVersion as the authoritative compatibility gate. Use a schema hash only as an optional same‑version drift check, and compute it on lightweight metadata (never the full payload) if you enable it.
A version number gives a fast, deterministic refusal or migration path for breaking changes. A schema hash can catch field‑level changes inside the same version, but its value depends on canonical serialization and adds hashing overhead; it is not reliable as the sole load gate.
love.filesystem stores opaque bytes; the save table must carry its own compatibility marker.formatVersion only for breaking save‑format changes (field removal, rename, type change).{ formatVersion = CURRENT_VERSION, schemaHash = OPTIONAL_HASH, data = ... }.formatVersion to the current integer; compute schemaHash only if you want drift detection and store it.love.filesystem.read and deserialize.formatVersion is missing or greater than CURRENT_VERSION, refuse or prompt for upgrade.formatVersion is less than CURRENT_VERSION, run the migration function for that version.schemaHash, compute the hash of the canonical schema descriptor and compare; on mismatch, log a warning or trigger a same‑version migration (only if you need drift detection).nil.Do you need to detect field‑level drift within the same version (e.g., for dev builds or early‑access testing)? If yes, keep the optional schema hash; if no, you can omit it entirely to save startup time.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.