HotEntryCache will update Instants only once per second

Calling Instant.now() several hundred thousand times per
second can be expensive. In my measurements >10% of the
time spend when loading new data was spend calling
Instant.now().
Fixed this by storing an Instant as static member and
updating it periodically in a separate thread.
This commit is contained in:
2018-12-21 19:16:55 +01:00
parent d95a71e32e
commit e537e94d39
4 changed files with 107 additions and 30 deletions

View File

@@ -152,7 +152,8 @@ public class DataStore implements AutoCloseable {
// A Doc will never be changed once it is created. Therefore we can cache them
// easily.
private final HotEntryCache<Long, Doc> docIdToDocCache = new HotEntryCache<>(Duration.ofMinutes(10));
private final HotEntryCache<Long, Doc> docIdToDocCache = new HotEntryCache<>(Duration.ofMinutes(10),
"docIdToDocCache");
private final DiskStorage diskStorage;
private final Path diskStorageFilePath;