...

Text file src/github.com/opencontainers/selinux/pkg/pwalkdir/README.md

Documentation: github.com/opencontainers/selinux/pkg/pwalkdir

     1## pwalkdir: parallel implementation of filepath.WalkDir
     2
     3This is a wrapper for [filepath.WalkDir](https://pkg.go.dev/path/filepath#WalkDir)
     4which may speed it up by calling multiple callback functions (WalkDirFunc)
     5in parallel, utilizing goroutines.
     6
     7By default, it utilizes 2\*runtime.NumCPU() goroutines for callbacks.
     8This can be changed by using WalkN function which has the additional
     9parameter, specifying the number of goroutines (concurrency).
    10
    11### pwalk vs pwalkdir
    12
    13This package is very similar to
    14[pwalk](https://pkg.go.dev/github.com/opencontainers/selinux/pkg/pwalkdir),
    15but utilizes `filepath.WalkDir` (added to Go 1.16), which does not call stat(2)
    16on every entry and is therefore faster (up to 3x, depending on usage scenario).
    17
    18Users who are OK with requiring Go 1.16+ should switch to this
    19implementation.
    20
    21### Caveats
    22
    23Please note the following limitations of this code:
    24
    25* Unlike filepath.WalkDir, the order of calls is non-deterministic;
    26
    27* Only primitive error handling is supported:
    28
    29  * fs.SkipDir is not supported;
    30
    31  * no errors are ever passed to WalkDirFunc;
    32
    33  * once any error is returned from any walkDirFunc instance, no more calls
    34    to WalkDirFunc are made, and the error is returned to the caller of WalkDir;
    35
    36  * if more than one WalkDirFunc instance will return an error, only one
    37    of such errors will be propagated to and returned by WalkDir, others
    38    will be silently discarded.
    39
    40### Documentation
    41
    42For the official documentation, see
    43https://pkg.go.dev/github.com/opencontainers/selinux/pkg/pwalkdir
    44
    45### Benchmarks
    46
    47For a WalkDirFunc that consists solely of the return statement, this
    48implementation is about 15% slower than the standard library's
    49filepath.WalkDir.
    50
    51Otherwise (if a WalkDirFunc is actually doing something) this is usually
    52faster, except when the WalkDirN(..., 1) is used. Run `go test -bench .`
    53to see how different operations can benefit from it, as well as how the
    54level of paralellism affects the speed.

View as plain text