Improve full data sample pooling logic

This commit is contained in:
James Seibel
2023-09-21 19:29:52 -05:00
parent 74cac0c263
commit 29d474c577
2 changed files with 13 additions and 9 deletions
@@ -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<IIncompleteFullDataSource> sampleFromFileArray(IIncompleteFullDataSource recipientFullDataSource, ArrayList<FullDataMetaFile> 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<IIncompleteFullDataSource> sampleFromFileArray(IIncompleteFullDataSource recipientFullDataSource, ArrayList<FullDataMetaFile> 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<IFullDataSource> loadFileFuture = cacheLoadedDataSources ? existingFile.getOrLoadCachedDataSourceAsync() : existingFile.getDataSourceWithoutCachingAsync();
CompletableFuture<IFullDataSource> loadFileFuture = usePooledDataSources ? existingFile.getOrLoadCachedDataSourceAsync() : existingFile.getDataSourceWithoutCachingAsync();
CompletableFuture<IFullDataSource> 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);
@@ -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<IFullDataSource> updateFromExistingDataSourcesAsync(FullDataMetaFile file, IIncompleteFullDataSource data)
private CompletableFuture<IFullDataSource> updateFromExistingDataSourcesAsync(FullDataMetaFile file, IIncompleteFullDataSource data, boolean usePooledDataSources)
{
DhSectionPos pos = file.pos;
ArrayList<FullDataMetaFile> 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<IFullDataSource> future = this.updateFromExistingDataSourcesAsync(file, data);
CompletableFuture<IFullDataSource> 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<IFullDataSource> future = this.updateFromExistingDataSourcesAsync(file, (IIncompleteFullDataSource) fullDataSource);
CompletableFuture<IFullDataSource> future = this.updateFromExistingDataSourcesAsync(file, (IIncompleteFullDataSource) fullDataSource, false);
if (future != null)
{
final boolean finalDataChanged = dataChanged;