From 9c8ab8458ec658aa3007c0e8c1695907c8d8c39f Mon Sep 17 00:00:00 2001 From: Gofastasf Date: Thu, 30 Jan 2025 02:10:40 +0000 Subject: all: replace Walk with WalkDir to reduce os.Lstat calls filepath.Walk calls os.Lstat for every file or directory to retrieve os.FileInfo. filepath.WalkDir avoids unnecessary system calls since it provides a fs.DirEntry, which includes file type information without requiring a stat call. This improves performance by reducing redundant system calls. --- pkg/cover/backend/modules.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pkg/cover') diff --git a/pkg/cover/backend/modules.go b/pkg/cover/backend/modules.go index fbce68a49..f44790e73 100644 --- a/pkg/cover/backend/modules.go +++ b/pkg/cover/backend/modules.go @@ -7,7 +7,7 @@ import ( "bytes" "debug/elf" "fmt" - "os" + "io/fs" "path/filepath" "strings" @@ -72,7 +72,7 @@ func discoverModulesLinux(dirs []string) ([]*vminfo.KernelModule, error) { func locateModules(dirs []string) (map[string]string, error) { paths := make(map[string]string) for _, dir := range dirs { - err := filepath.Walk(dir, func(path string, f os.FileInfo, err error) error { + err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error { if err != nil || filepath.Ext(path) != ".ko" { return err } -- cgit mrf-deployment