Skip to content

Commit 0e5674f

Browse files
committed
ls: compute relparts once for every dir
Cuts down `dvc ls . data/mnist/dataset --recursive` for me from ~25 to ~12 seconds. `relparts` is an expensive operation as it calls `relpath` that calls `abspath`, so we want to avoid calling it as much as possible.
1 parent 684fc32 commit 0e5674f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

dvc/repo/ls.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,12 @@ def _ls(
7070
if not recursive:
7171
files.update(dirs)
7272

73+
parts = fs.path.relparts(root, fs_path)
74+
if parts == (".",):
75+
parts = ()
76+
7377
for name, entry in files.items():
74-
entry_fs_path = fs.path.join(root, name)
75-
relparts = fs.path.relparts(entry_fs_path, fs_path)
76-
name = os.path.join(*relparts)
77-
infos[name] = entry
78+
infos[os.path.join(*parts, name)] = entry
7879

7980
if not recursive:
8081
break

0 commit comments

Comments
 (0)