Skip to content

Remove redundant ReadDir() calls in isSingleChild

Administrator requested to merge lg/fix-tree-resolver into master

Created by: lguychard

Rel https://github.com/sourcegraph/customer/issues/23

A customer (https://app.hubspot.com/contacts/2762526/company/554275594) reported that the files sidebar was slow to load, even though the "Files and directories" section of the main tree view, which displays basically the same information, was not.

The graphQL query for the sidebar (in fetchTreeEntries()) requested the following additional fields for each tree entry:

submodule {
    url
    commit
}
isSingleChild

In my tests, submodule did not affect performance, but isSingleChild did, causing up to a 50% perf hit for the same repository/commit/path even for small repositories.

Looking at the resolvers, I realised that the IsSingleChild() resolver performed a git.ReadDir() of the parent directory for each entry. This meant that the query was resulting in N+1 git.ReadDir() calls for the same directory, where N is the number of entries in that directory.

Merge request reports

Loading