Skip to content
Snippets Groups Projects
Commit ad3ecac9 authored by Pierre-Yves David's avatar Pierre-Yves David
Browse files

model: avoid another extra creation of Model object

Do not create model object while sorting entry before creating model
object.

This is another case of "let us create object X to prepare the creation
of object X", slowing things down.

In practice, we will likely skip this code-path after the next
changeset, however this seems useful to get this performance footgun
out the way.

We tested this change on simple information of the Mercurial loader,
with a noop-loader stockage:

    swh loader run mercurial https://foss.heptapod.net/mercurial/mercurial-devel directory=/data/repos/mercurial-devel

= Median time of 3 run =
before  12 minutes 59 seconds
after:  11 minute  56 seconds

On a profile of the same run, the `to_model` call of the from_disk's `Directory` class took the following percentage:
before: 24%
after:  17%
parent 814a6c84
No related branches found
No related tags found
No related merge requests found
......@@ -55,12 +55,16 @@ def content_git_object(content: model.Content) -> bytes:
def directory_entry_sort_key(entry: model.DirectoryEntry):
"""The sorting key for tree entries"""
if isinstance(entry, dict):
# For backward compatibility
entry = model.DirectoryEntry.from_dict(entry)
if entry.type == "dir":
return entry.name + b"/"
type_ = entry["type"]
name = entry["name"]
else:
type_ = entry.type
name = entry.name
if type_ == "dir":
return name + b"/"
else:
return entry.name
return name
@lru_cache()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment