From 484b44739153495d5cb748c1c17b27234edbd052 Mon Sep 17 00:00:00 2001 From: Chris Allen Lane Date: Thu, 4 Aug 2022 19:26:07 -0400 Subject: [PATCH] perf(Sheets): do not walk hidden directories Modify `Sheets.Load` to not walk hidden directories like `.git`. This optimization can potentially prevent thousands of system calls from being made, because `.git` directories can contain many files. --- internal/sheets/load.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/sheets/load.go b/internal/sheets/load.go index 409f505..0d88c24 100644 --- a/internal/sheets/load.go +++ b/internal/sheets/load.go @@ -2,6 +2,7 @@ package sheets import ( "fmt" + "io/fs" "os" "path/filepath" "strings" @@ -55,7 +56,11 @@ func Load(cheatpaths []cp.Cheatpath) ([]map[string]sheet.Sheet, error) { // contained within hidden directories in the middle of a path, though // that should not realistically occur. if strings.HasPrefix(title, ".") || strings.HasPrefix(info.Name(), ".") { - return nil + // Do not walk hidden directories. This is important, + // because it's common for cheatsheets to be stored in + // version-control, and a `.git` directory can easily + // contain thousands of files. + return fs.SkipDir } // parse the cheatsheet file into a `sheet` struct