Skip to content

Performance improvement #16

@cg110

Description

@cg110

Hi,

I was using this tool to fixup some directory casing problems, IE:
git-unite -d

And found that it was very slow progress. This appears to be due to the code for indexEntries being quite slow, as we've 40-50k files in the index, and paths.

I did a bit of an optimization, and altered the code here:
https://github.com/tawman/git-unite/blob/master/src/LibGitUnite/UniteRepository.cs#L156

To

var indexEntries =
                _gitRepository.Index.Where(f =>
                {
                    var lastSeparator = f.Path.LastIndexOf(CharSeparator);

                    if (lastSeparator == -1)
                        return false;

                    var directoryPath = f.Path.Substring(0, lastSeparator);

                    return !foldersFullPathMap.Any(s => s.Contains(directoryPath));

                    //return f.Path.LastIndexOf(Separator, StringComparison.Ordinal) != -1
                    //       &&
                    //       !foldersFullPathMap.Any(s =>
                    //           s.Contains(f.Path.Substring(0,
                    //               f.Path.LastIndexOf(Separator, StringComparison.Ordinal))));
                });

Note that I also added a CharSeparator:
private const char CharSeparator = '\';

Testing on an i9-9900k with ssd, git-unite 2.1 takes 6m25s

With the above optimizations it takes 2m26s. I did wonder if more can be done, eg make the foldersFullPathMap only have the git paths in, rather than the full path.

Still it's a 50% reduction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions