Skip to content

Commit cec29ba

Browse files
authored
Store sizes in CachingFileSystem for performance (#1833)
1 parent b60dac4 commit cec29ba

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

fsspec/implementations/cached.py

+12
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ def _open(
335335
self._metadata.update_file(path, detail)
336336
logger.debug("Creating local sparse file for %s", path)
337337

338+
# explicitly submitting the size to the open call will avoid extra
339+
# operations when opening. This is particularly relevant
340+
# for any file that is read over a network, e.g. S3.
341+
size = detail.get("size", None)
342+
338343
# call target filesystems open
339344
self._mkcache()
340345
f = self.fs._open(
@@ -344,8 +349,15 @@ def _open(
344349
autocommit=autocommit,
345350
cache_options=cache_options,
346351
cache_type="none",
352+
size=size,
347353
**kwargs,
348354
)
355+
356+
# set size if not already set
357+
if size is None:
358+
detail["size"] = f.size
359+
self._metadata.update_file(path, detail)
360+
349361
if self.compression:
350362
comp = (
351363
infer_compression(path)

0 commit comments

Comments
 (0)