diff --git a/CHANGELOG.md b/CHANGELOG.md index 22bd963f9..3d4da4953 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - When converting girder images locally, prefer mount paths ([886](../../pull/886)) - Store the id of job results for easier post-job work ([887](../../pull/887)) - Harden style compositing of partial tiles ([889](../../pull/889)) +- Cache read_tiff calls to speed up restyling ([891](../../pull/891)) ### Changes - Be more consistent in source class name attribute assignment ([884](../../pull/884)) diff --git a/sources/tiff/large_image_source_tiff/__init__.py b/sources/tiff/large_image_source_tiff/__init__.py index 0b33afc36..992b993cc 100644 --- a/sources/tiff/large_image_source_tiff/__init__.py +++ b/sources/tiff/large_image_source_tiff/__init__.py @@ -21,6 +21,7 @@ import math import os +import cachetools import numpy import PIL.Image import tifftools @@ -48,6 +49,11 @@ pass +@cachetools.cached(cache=cachetools.LRUCache(maxsize=10)) +def _cached_read_tiff(path): + return tifftools.read_tiff(path) + + class TiffFileTileSource(FileTileSource, metaclass=LruCacheMetaclass): """ Provides tile access to TIFF files. @@ -264,7 +270,7 @@ def _initWithTiffTools(self): # noqa self.levels = max(1, int(math.ceil(math.log(max( dir0.imageWidth / dir0.tileWidth, dir0.imageHeight / dir0.tileHeight)) / math.log(2))) + 1) - info = tifftools.read_tiff(self._largeImagePath) + info = _cached_read_tiff(self._largeImagePath) frames = [] associated = [] # for now, a list of directories curframe = -1