import megamek.common.loaders.MekSummaryCache; /** * Force MegaMek to build data/mekfiles/units.cache at image-build time. * *

MegaMek does not ship the cache. Building it means walking ~11k unit files: * 20.2s cold versus 2.9s to load a prebuilt one. Paying that once per image * instead of once per match is the single largest cold-start saving measured. * *

Run with the single-file source launcher against the stock jar; it needs no * compiler in the runtime image because only the resulting cache file is copied * forward. Must run with MegaMek's install dir as the working directory - * MegaMek resolves data/ relative to cwd. */ public final class PrimeUnitsCache { public static void main(String[] args) throws Exception { long start = System.currentTimeMillis(); MekSummaryCache cache = MekSummaryCache.getInstance(); long deadline = start + 300_000L; while (!cache.isInitialized()) { if (System.currentTimeMillis() > deadline) { System.err.println("units.cache did not initialise within 300s"); System.exit(1); } Thread.sleep(250L); } System.out.printf("units.cache primed in %.1fs%n", (System.currentTimeMillis() - start) / 1000.0); } }