From f3fb8d0a22b7425dca66b4dcd4473a5b6a749be0 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 24 Feb 2026 17:25:05 +0100 Subject: [PATCH] skargo: use per-unit state.db to avoid cache thrashing Lib and test targets sharing the same build directory and relocation model would read/write the same state.db, causing cache thrashing. Include the package name and unit hash in the state.db filename to make it unique per compilation unit. Co-Authored-By: Claude Opus 4.6 --- skiplang/skargo/src/build_runner.sk | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/skiplang/skargo/src/build_runner.sk b/skiplang/skargo/src/build_runner.sk index f4fb19b26..a185b0ab1 100644 --- a/skiplang/skargo/src/build_runner.sk +++ b/skiplang/skargo/src/build_runner.sk @@ -391,11 +391,16 @@ mutable class BuildRunner( if (!unit.target.is_build_script()) { // TODO: Once we have namespaced packages, we can share the state.db // across architectures. + // Also split by unit to avoid cache thrashing between lib and test + // targets that share the same build directory. + unit_hash = this.hashes[unit].toStringHex(); state_db_path = Path.join( this.layout_for(unit).build, // FIXME: This is a dirty hack that splits out the state.db between pic // and static, which is required until `skc` namespaces packages. - `${unit.build_opts.relocation_model}_state.db`, + `${unit.pkg.name()}-${unit_hash}_${ + unit.build_opts.relocation_model + }_state.db`, ); skc.args( Array[