Skip to content

Commit 854f005

Browse files
committed
Cache: don't invalidate by timestamp, only rebuild if missing
1 parent a5d2aa8 commit 854f005

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

src/java/CppBuild.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,19 +3055,21 @@ private List<String> buildCommand(String gpp, File src, File bin, boolean win, b
30553055
// Skip PCH on low-memory machines (< 4GB free) to avoid OOM
30563056
long freeMemBytes = Runtime.getRuntime().maxMemory() -
30573057
(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
3058-
boolean lowMemory = freeMemBytes < 512L * 1024 * 1024; // < 512MB JVM headroom
3058+
boolean lowMemory = freeMemBytes < 768L * 1024 * 1024; // < 768MB JVM headroom
30593059
// Also check system RAM
30603060
try {
3061-
// Use reflection to avoid hard dependency on com.sun.management
30623061
java.lang.management.OperatingSystemMXBean osmx =
30633062
java.lang.management.ManagementFactory.getOperatingSystemMXBean();
30643063
java.lang.reflect.Method getFreeMemory =
30653064
osmx.getClass().getMethod("getFreeMemorySize");
30663065
getFreeMemory.setAccessible(true);
30673066
long freeRam = (long) getFreeMemory.invoke(osmx);
3068-
if (freeRam < 2L * 1024 * 1024 * 1024) lowMemory = true;
3067+
if (freeRam < 3L * 1024 * 1024 * 1024) lowMemory = true; // < 3GB free RAM
30693068
} catch (Exception ignored) {}
3070-
if (lowMemory) needsPch = false;
3069+
if (lowMemory) {
3070+
needsPch = false;
3071+
listener.statusNotice("Low memory detected — skipping PCH cache (compile may be slower)");
3072+
}
30713073
try {
30723074
String osName = System.getProperty("os.name","").toLowerCase();
30733075
String cacheSubDir = osName.contains("win") ? "cache/windows-x64"
@@ -3077,17 +3079,13 @@ private List<String> buildCommand(String gpp, File src, File bin, boolean win, b
30773079
cacheDir.mkdirs();
30783080
File processingH = new File(runtimeDir, "Processing.h");
30793081
processingPch = new File(cacheDir, "Processing.h.gch");
3080-
needsPch = !processingPch.exists()
3081-
|| (processingH.exists() && processingH.lastModified() > processingPch.lastModified());
3082+
needsPch = !processingPch.exists();
30823083
File processingO = new File(cacheDir, "Processing.o");
30833084
File defaultsO = new File(cacheDir, "Processing_defaults.o");
30843085
File processingCpp = new File(runtimeDir, "Processing.cpp");
30853086
File defaultsCpp = new File(runtimeDir, "Processing_defaults.cpp");
3086-
boolean needsProcessing = !processingO.exists()
3087-
|| processingCpp.lastModified() > processingO.lastModified()
3088-
|| (processingH.exists() && processingH.lastModified() > processingO.lastModified());
3089-
boolean needsDefaults = !defaultsO.exists()
3090-
|| defaultsCpp.lastModified() > defaultsO.lastModified();
3087+
boolean needsProcessing = !processingO.exists();
3088+
boolean needsDefaults = !defaultsO.exists();
30913089

30923090
if (needsPch) {
30933091
List<String> pchCmd = new ArrayList<>();

0 commit comments

Comments
 (0)