Skip to content

perf(plugin): optimize directory traversal by replacing filepath.Walk with filepath.WalkDir#10325

Open
ankit98040 wants to merge 1 commit intoaquasecurity:mainfrom
ankit98040:perf/optimize-filepath-walkdir
Open

perf(plugin): optimize directory traversal by replacing filepath.Walk with filepath.WalkDir#10325
ankit98040 wants to merge 1 commit intoaquasecurity:mainfrom
ankit98040:perf/optimize-filepath-walkdir

Conversation

@ankit98040
Copy link
Contributor

@ankit98040 ankit98040 commented Mar 5, 2026

Description

perf(plugin): optimize directory traversal with filepath.WalkDir

Prior to Go 1.16, filepath.Walk invoked os.Lstat on every visited file or directory to retrieve a heavy fs.FileInfo object, causing a significant performance bottleneck due to excessive system calls.

This commit replaces filepath.Walk with the more performant filepath.WalkDir API in the pkg/module package. The newer API passes an fs.DirEntry instead, which utilizes cached directory entry information provided by modern operating systems during the initial directory read.

This optimization minimizes unnecessary lstat syscalls over large directory structures when loading WebAssembly modules, significantly improving filesystem traversal speed and reducing CPU overhead.

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

… with filepath.WalkDir

Prior to Go 1.16, `filepath.Walk` invoked `os.Lstat` on every visited file or directory to retrieve a heavy `fs.FileInfo` object, causing a significant performance bottleneck due to excessive system calls.

This commit replaces `filepath.Walk` with the more performant `filepath.WalkDir` API in the `pkg/module` package. The newer API passes an `fs.DirEntry` instead, which utilizes cached directory entry information provided by modern operating systems during the initial directory read.

This optimization minimizes unnecessary `lstat` syscalls over large directory structures when loading WebAssembly modules, significantly improving filesystem traversal speed and reducing CPU overhead.
@ankit98040 ankit98040 requested a review from knqyf263 as a code owner March 5, 2026 03:45
@ankit98040 ankit98040 changed the title perf(module): optimize directory traversal by replacing filepath.Walk with filepath.WalkDir perf(plugin): optimize directory traversal by replacing filepath.Walk with filepath.WalkDir Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant