Skip to content

Commit 45c2c72

Browse files
authored
remote: don't use PathInfo.from_posix (#3637)
Using it to load dirs takes around 50 sec compared to 0.4 with simple `replace()`. Path objects are great, but not when you need lots of them. Related to #3635
1 parent d3d471c commit 45c2c72

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

dvc/path_info.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ def __new__(cls, *args):
3333
cls = WindowsPathInfo if os.name == "nt" else PosixPathInfo
3434
return cls._from_parts(args)
3535

36-
@classmethod
37-
def from_posix(cls, s):
38-
return cls(PosixPathInfo(s))
39-
4036
def as_posix(self):
4137
f = self._flavour
4238
# Unlike original implementation [1] that uses `str()` we actually need

dvc/remote/base.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
RemoteCacheRequiredError,
2222
)
2323
from dvc.ignore import DvcIgnore
24-
from dvc.path_info import PathInfo, URLInfo
24+
from dvc.path_info import PathInfo, URLInfo, WindowsPathInfo
2525
from dvc.progress import Tqdm
2626
from dvc.remote.slow_link_detection import slow_link_guard
2727
from dvc.state import StateNoop
@@ -285,10 +285,13 @@ def load_dir_cache(self, checksum):
285285
)
286286
return []
287287

288-
for info in d:
289-
# NOTE: here is a BUG, see comment to .as_posix() below
290-
relative_path = PathInfo.from_posix(info[self.PARAM_RELPATH])
291-
info[self.PARAM_RELPATH] = relative_path.fspath
288+
if self.path_cls == WindowsPathInfo:
289+
# only need to convert it for Windows
290+
for info in d:
291+
# NOTE: here is a BUG, see comment to .as_posix() below
292+
info[self.PARAM_RELPATH] = info[self.PARAM_RELPATH].replace(
293+
"/", self.path_cls.sep
294+
)
292295

293296
return d
294297

0 commit comments

Comments
 (0)