-
-
Notifications
You must be signed in to change notification settings - Fork 110
Possibly better cache strategy for FileSystem #617
Copy link
Copy link
Closed
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomersimprovementnew feature, improve in readability, structure or performancenew feature, improve in readability, structure or performance
Description
Lines 551 to 575 in 8ac5289
| // We cache the FileSystem instances as their creation is expensive. | |
| // The Guava Cache is thread-safe (see JavaDoc of LoadingCache) hence this | |
| // cache can be safely shared in a static variable. | |
| protected static final LoadingCache<Path, FileSystem> fileSystemCache = | |
| CacheBuilder.newBuilder() | |
| .removalListener( | |
| (RemovalNotification<Path, FileSystem> removalNotification) -> { | |
| try { | |
| removalNotification.getValue().close(); | |
| } catch (IOException e) { | |
| throw new RuntimeException( | |
| "Could not close file system of " + removalNotification.getKey(), e); | |
| } | |
| }) | |
| .expireAfterAccess(1, TimeUnit.SECONDS) | |
| .build( | |
| CacheLoader.from( | |
| path -> { | |
| try { | |
| return FileSystems.newFileSystem( | |
| Objects.requireNonNull(path), (ClassLoader) null); | |
| } catch (IOException e) { | |
| throw new RuntimeException("Could not open file system of " + path, e); | |
| } | |
| })); |
I think it is better to use reference-based eviction instead of timed eviction, that is CacheBuilder.weakValues().
Firstly, in this way, we can use cached FileSystem in:
Lines 600 to 608 in 8ac5289
| // we don't use the filesystem cache here as it could close the filesystem after the timeout | |
| // while we are still iterating | |
| try (FileSystem fs = FileSystems.newFileSystem(path, (ClassLoader) null)) { | |
| final Path archiveRoot = fs.getPath("/"); | |
| return walkDirectory( | |
| archiveRoot, view.getProject().getIdentifierFactory(), new AsmJavaClassProvider(view)); | |
| } catch (IOException e) { | |
| throw new RuntimeException(e); | |
| } |
Secondly, MultiReleaseJarAnalysisInputLocation.discoverInputLocations adds archiveRoot to inputLocations:
Line 307 in 8ac5289
| baseInputLocations.add(new PathBasedAnalysisInputLocation(archiveRoot, srcType)); |
This archiveRoot is a DirectoryBasedAnalysisInputLocation. It uses its
path's FileSystem in getClassSources, getClassSource and some other methods. If the FileSystem is used after closed (1 second timeout), it will cause a ClosedFileSystemException.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomersimprovementnew feature, improve in readability, structure or performancenew feature, improve in readability, structure or performance