diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataFileHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataFileHandler.java index 2b6d4af7e..ab63d40f4 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataFileHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/FullDataFileHandler.java @@ -377,8 +377,12 @@ public class FullDataFileHandler implements IFullDataSourceProvider LowDetailIncompleteFullDataSource.createEmpty(pos); } - /** populates the given data source using the given array of files */ - protected CompletableFuture sampleFromFileArray(IIncompleteFullDataSource recipientFullDataSource, ArrayList existingFiles, boolean cacheLoadedDataSources) + /** + * Populates the given data source using the given array of files + * @param usePooledDataSources if enabled the data sources necessary for this sampling will not be stored beyond what is necessary for the sampling. + * This helps reduce garbage collector pressure if the data sources will never be used again. + */ + protected CompletableFuture sampleFromFileArray(IIncompleteFullDataSource recipientFullDataSource, ArrayList existingFiles, boolean usePooledDataSources) { boolean showFullDataFileSampling = Config.Client.Advanced.Debugging.DebugWireframe.showFullDataFileSampling.get(); if (showFullDataFileSampling) @@ -395,7 +399,7 @@ public class FullDataFileHandler implements IFullDataSourceProvider FullDataMetaFile existingFile = existingFiles.get(i); - CompletableFuture loadFileFuture = cacheLoadedDataSources ? existingFile.getOrLoadCachedDataSourceAsync() : existingFile.getDataSourceWithoutCachingAsync(); + CompletableFuture loadFileFuture = usePooledDataSources ? existingFile.getOrLoadCachedDataSourceAsync() : existingFile.getDataSourceWithoutCachingAsync(); CompletableFuture sampleSourceFuture = loadFileFuture.whenComplete((existingFullDataSource, ex) -> { @@ -424,7 +428,7 @@ public class FullDataFileHandler implements IFullDataSourceProvider } // pooling temporary data sources massively reduces garbage collector overhead when just sampling (going from ~8 GB/sec to ~90 MB/sec) - if (!cacheLoadedDataSources && !existingFile.cacheLoadingDataSource) + if (!usePooledDataSources && !existingFile.cacheLoadingDataSource) { existingFile.clearCachedDataSource(); @@ -479,7 +483,7 @@ public class FullDataFileHandler implements IFullDataSourceProvider else { this.makeFiles(missing, existFiles); - return this.sampleFromFileArray(source, existFiles, false).thenApply(IIncompleteFullDataSource::tryPromotingToCompleteDataSource) + return this.sampleFromFileArray(source, existFiles, true).thenApply(IIncompleteFullDataSource::tryPromotingToCompleteDataSource) .exceptionally((e) -> { FullDataMetaFile newMetaFile = this.removeCorruptedFile(pos, file, e); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataFileHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataFileHandler.java index e20c89636..b6aaaf224 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataFileHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/file/fullDatafile/GeneratedFullDataFileHandler.java @@ -170,7 +170,7 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandler // Try update the gen queue on this data source. If null, then nothing was done. @Nullable - private CompletableFuture updateFromExistingDataSourcesAsync(FullDataMetaFile file, IIncompleteFullDataSource data) + private CompletableFuture updateFromExistingDataSourcesAsync(FullDataMetaFile file, IIncompleteFullDataSource data, boolean usePooledDataSources) { DhSectionPos pos = file.pos; ArrayList existingFiles = new ArrayList<>(); @@ -186,7 +186,7 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandler { // There are other data source files to sample from. this.makeFiles(missingPositions, existingFiles); - return this.sampleFromFileArray(data, existingFiles, true) + return this.sampleFromFileArray(data, existingFiles, usePooledDataSources) .thenApply(this::tryPromoteDataSource) .exceptionally((e) -> { @@ -201,7 +201,7 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandler { DhSectionPos pos = file.pos; IIncompleteFullDataSource data = this.makeEmptyDataSource(pos); - CompletableFuture future = this.updateFromExistingDataSourcesAsync(file, data); + CompletableFuture future = this.updateFromExistingDataSourcesAsync(file, data, true); // Cant start gen task, so return the data return future == null ? CompletableFuture.completedFuture(data) : future; } @@ -224,7 +224,7 @@ public class GeneratedFullDataFileHandler extends FullDataFileHandler IWorldGenerationQueue worldGenQueue = this.worldGenQueueRef.get(); if (worldGenQueue != null) { - CompletableFuture future = this.updateFromExistingDataSourcesAsync(file, (IIncompleteFullDataSource) fullDataSource); + CompletableFuture future = this.updateFromExistingDataSourcesAsync(file, (IIncompleteFullDataSource) fullDataSource, false); if (future != null) { final boolean finalDataChanged = dataChanged;