Skip to content

fileserver: speed up directory browsing for large directories - #7903

Merged
steadytao merged 11 commits into
caddyserver:masterfrom
firefart:fileserver
Jul 31, 2026
Merged

steadytao merged 11 commits into
caddyserver:masterfrom
firefart:fileserver

Conversation

@firefart

@firefart firefart commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7902

The Benchmarks in this PR and the unused functions can be deleted after the PR is merged (hopefully :)). They are kept to measure the actual difference on big directories using golang benchmarks

Assistance Disclosure

Claude was used to generate the benchmarks, tests, verify the implementation, add comments and generate a good PR description

Description

Directory browsing (browse) was slow for directories with tens of thousands
of entries due to allocation-heavy listing construction and an O(n log n)
strings.ToLower recomputation in the sort comparators (called on every
single comparison instead of once per item).

Changes

  • directoryListing (listing construction): preallocates the Items
    slice instead of growing it via unprepended append, and merges the two
    separate Stat calls the old code made per symlink (one to check if the
    target is a dir, one to get its size) into one.
  • applySortAndLimit (sorting): precomputes each item's lowercase name
    once, up front, instead of letting byName/byNameDirFirst/bySize
    recompute it on every one of the O(n log n) comparisons sort.Sort makes.
  • No public API changes — every touched function/type is unexported.
  • The previous implementations are kept temporarily as directoryListingOld,
    applySortAndLimitOld, byNameOld, byNameDirFirstOld, bySizeOld
    (//nolint:unused), used only by the benchmarks/parity tests below, so
    reviewers can compare old vs. new directly. These should be deleted once
    this PR is reviewed/merged.
  • Added TestDirectoryListingParity and TestApplySortAndLimitParity,
    which assert old and new produce identical output/ordering.

Benchmarks

Machine: AMD Ryzen 7 9700X, go test -bench Benchmark -benchtime=10x, real
on-disk temp directories (not in-memory fakes), directory entries read via
the same unsorted, filesystem-order ReadDir call path production uses.

BenchmarkDirectoryListingOld/entries=100-16                  10       182318 ns/op    77616 B/op     567 allocs/op
BenchmarkDirectoryListingOld/entries=1000-16                 10      1772123 ns/op   812464 B/op    5071 allocs/op
BenchmarkDirectoryListingOld/entries=10000-16                10     20022405 ns/op  8685831 B/op   50079 allocs/op
BenchmarkDirectoryListingOld/entries=50000-16                10    102706521 ns/op 47649628 B/op  250087 allocs/op
BenchmarkDirectoryListingNew/entries=100-16                  10       191390 ns/op    56416 B/op     542 allocs/op
BenchmarkDirectoryListingNew/entries=1000-16                 10      1696584 ns/op   533216 B/op    5042 allocs/op
BenchmarkDirectoryListingNew/entries=10000-16                10     18533901 ns/op  5284854 B/op   50042 allocs/op
BenchmarkDirectoryListingNew/entries=50000-16                10     96067873 ns/op 26406439 B/op  250043 allocs/op
BenchmarkSortByNameOld/entries=100-16                        10        42816 ns/op    10432 B/op     641 allocs/op
BenchmarkSortByNameOld/entries=1000-16                       10       652659 ns/op   209120 B/op   13059 allocs/op
BenchmarkSortByNameOld/entries=10000-16                      10      8090392 ns/op  2855003 B/op  178426 allocs/op
BenchmarkSortByNameOld/entries=50000-16                      10     46858369 ns/op 16861105 B/op 1053806 allocs/op
BenchmarkSortByNameNew/entries=100-16                        10         7128 ns/op      192 B/op       1 allocs/op
BenchmarkSortByNameNew/entries=1000-16                       10        88274 ns/op      192 B/op       1 allocs/op
BenchmarkSortByNameNew/entries=10000-16                      10      1225277 ns/op      192 B/op       1 allocs/op
BenchmarkSortByNameNew/entries=50000-16                      10      7166846 ns/op      192 B/op       1 allocs/op
BenchmarkSortByNameDirFirstOld/entries=100-16                10        20864 ns/op     7024 B/op     428 allocs/op
BenchmarkSortByNameDirFirstOld/entries=1000-16               10       356464 ns/op   132320 B/op    8259 allocs/op
BenchmarkSortByNameDirFirstOld/entries=10000-16              10      5888664 ns/op  1954539 B/op  122147 allocs/op
BenchmarkSortByNameDirFirstOld/entries=50000-16              10     41926913 ns/op 13416300 B/op  838505 allocs/op
BenchmarkSortByNameDirFirstNew/entries=100-16                10         4940 ns/op      192 B/op       1 allocs/op
BenchmarkSortByNameDirFirstNew/entries=1000-16               10        49687 ns/op      192 B/op       1 allocs/op
BenchmarkSortByNameDirFirstNew/entries=10000-16              10       708212 ns/op      192 B/op       1 allocs/op
BenchmarkSortByNameDirFirstNew/entries=50000-16              10      7280534 ns/op      192 B/op       1 allocs/op
BenchmarkSortBySizeOld/entries=100-16                        10        12664 ns/op     1056 B/op      55 allocs/op
BenchmarkSortBySizeOld/entries=1000-16                       10       126611 ns/op    23168 B/op    1437 allocs/op
BenchmarkSortBySizeOld/entries=10000-16                      10      1562636 ns/op   334944 B/op   20923 allocs/op
BenchmarkSortBySizeOld/entries=50000-16                      10      9118010 ns/op  2130688 B/op  133157 allocs/op
BenchmarkSortBySizeNew/entries=100-16                        10         6800 ns/op      192 B/op       1 allocs/op
BenchmarkSortBySizeNew/entries=1000-16                       10        66962 ns/op      192 B/op       1 allocs/op
BenchmarkSortBySizeNew/entries=10000-16                      10       599318 ns/op      192 B/op       1 allocs/op
BenchmarkSortBySizeNew/entries=50000-16                      10      3402615 ns/op      192 B/op       1 allocs/op
BenchmarkDirectoryListingAndSortOld/entries=100-16           10       196082 ns/op    77952 B/op     568 allocs/op
BenchmarkDirectoryListingAndSortOld/entries=1000-16          10      2315696 ns/op   812864 B/op    5072 allocs/op
BenchmarkDirectoryListingAndSortOld/entries=10000-16         10     22130926 ns/op  8829649 B/op   50079 allocs/op
BenchmarkDirectoryListingAndSortOld/entries=50000-16         10    131197667 ns/op 49231273 B/op  250086 allocs/op
BenchmarkDirectoryListingAndSortNew/entries=100-16           10       177454 ns/op    56704 B/op     543 allocs/op
BenchmarkDirectoryListingAndSortNew/entries=1000-16          10      1858050 ns/op   533569 B/op    5043 allocs/op
BenchmarkDirectoryListingAndSortNew/entries=10000-16         10     19413841 ns/op  5587563 B/op   50043 allocs/op
BenchmarkDirectoryListingAndSortNew/entries=50000-16         10    103014208 ns/op 27830187 B/op  250043 allocs/op

Speedup summary (ns/op, higher entry counts are the representative case):

Benchmark 1,000 10,000 50,000
DirectoryListing (build only) 4.3% faster 7.4% faster 6.5% faster / 44.6% less memory
SortByName 7.4x faster 6.6x faster 6.5x faster
SortByNameDirFirst (default) 7.2x faster 8.3x faster 5.8x faster
SortBySize 1.9x faster 2.6x faster 2.7x faster
DirectoryListingAndSort (whole request path) 19.8% faster 12.3% faster 21.5% faster / 43.5% less memory

Wall-clock time on DirectoryListing/DirectoryListingAndSort is bounded
by the lstat syscall per entry (needed for size/mtime and inherent to the
feature), so the gain there is more modest than the sort comparators, whose
ToLower-per-comparison cost is pure CPU/allocation waste that's now gone
entirely. Memory allocated drops by ~43–45% at 50,000 entries either way.

Copilot AI review requested due to automatic review settings July 23, 2026 20:38
@CLAassistant

CLAassistant commented Jul 23, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes the file server’s directory browsing path for very large directories by reducing avoidable allocations during listing construction and removing repeated strings.ToLower() work from sort comparisons.

Changes:

  • Preallocates the directory listing Items slice and reduces redundant stat calls for symlinks during listing construction.
  • Speeds up sorting by caching each item’s lowercase name once instead of recomputing it in every comparator call.
  • Adds parity tests and benchmarks comparing “old” vs “new” implementations (with old implementations temporarily retained for benchmarking).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
modules/caddyhttp/fileserver/browsetplcontext.go Optimizes directory listing construction and sorting; adds temporary “Old” implementations and cached lowercase name field.
modules/caddyhttp/fileserver/browsetplcontext_test.go Adds parity tests to ensure optimized behavior matches previous output.
modules/caddyhttp/fileserver/browsetplcontext_bench_test.go Adds benchmarks to measure old vs new performance on large directories and sorting.
modules/caddyhttp/fileserver/browse.go Marks isSymlinkTargetDir as unused (temporarily) for benchmark comparison support.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings July 25, 2026 18:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (3)

modules/caddyhttp/fileserver/browsetplcontext_test.go:148

  • Using os.DirFS(dir) here means the code will attempt fs.Stat/os.Readlink with absolute paths (built via SanitizedPathJoin(root, ...)), which DirFS will reject; that makes the parity test less representative of real browse behavior for symlinks. Use filesystems.OsFS and read entries from the absolute dir path instead.
	fileSystem := os.DirFS(dir)
	entries, err := fileSystem.(fs.ReadDirFS).ReadDir(".")
	if err != nil {
		t.Fatal(err)
	}

modules/caddyhttp/fileserver/browsetplcontext_bench_test.go:78

  • Using os.DirFS(dir) here causes fs.Stat inside directoryListing (for symlink target inspection) to be called with absolute paths, which DirFS rejects. That means the benchmark is not measuring the real stat/syscall behavior that browse uses in production. Use filesystems.OsFS{} and open the absolute dir path so ReadDir returns filesystem-order entries without the DirFS absolute-path mismatch.
	fileSystem := os.DirFS(dir)
	f, err := fileSystem.Open(".")
	if err != nil {
		tb.Fatal(err)
	}

modules/caddyhttp/fileserver/browsetplcontext.go:349

  • applySortAndLimit precomputes nameLower for every item even when sorting by time (or if sorting is skipped). That adds an unconditional O(n) allocation/cpu cost on every browse response, including cases where byTime is selected and nameLower is never read. Consider computing the cache only for sort modes that actually consult nameLower (name, namedirfirst, size).
	// precompute each item's lowercase name once, up front (O(n)), instead
	// of letting byName/byNameDirFirst/bySize recompute it on every one of
	// the O(n log n) comparisons sort.Sort makes
	for i := range l.Items {
		l.Items[i].nameLower = strings.ToLower(l.Items[i].Name)

Copilot AI review requested due to automatic review settings July 25, 2026 18:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

modules/caddyhttp/fileserver/browsetplcontext.go:350

  • The nameLower cache is computed unconditionally, even when sorting by time (or when no name-based sort is selected). For large directories this adds an extra O(n) scan and potentially many allocations that provide no benefit unless the comparator needs nameLower (name/namedirfirst/size).
	// precompute each item's lowercase name once, up front (O(n)), instead
	// of letting byName/byNameDirFirst/bySize recompute it on every one of
	// the O(n log n) comparisons sort.Sort makes
	for i := range l.Items {
		l.Items[i].nameLower = strings.ToLower(l.Items[i].Name)
	}

Comment thread modules/caddyhttp/fileserver/browse.go Resolved
Copilot AI review requested due to automatic review settings July 25, 2026 18:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (5)

modules/caddyhttp/fileserver/browsetplcontext.go:350

  • applySortAndLimit now lowercases every item name unconditionally, even when sorting by time (byTime doesn’t use name comparisons). For large directories, a user-requested sort=time becomes an O(n) extra allocation/CPU cost that wasn’t present before; consider filling nameLower only for the name-based comparators.
	// precompute each item's lowercase name once, up front (O(n)), instead
	// of letting byName/byNameDirFirst/bySize recompute it on every one of
	// the O(n log n) comparisons sort.Sort makes
	for i := range l.Items {
		l.Items[i].nameLower = strings.ToLower(l.Items[i].Name)
	}

modules/caddyhttp/fileserver/browsetplcontext_test.go:28

  • The parity test needs an fs.FS that accepts the absolute paths produced by caddyhttp.SanitizedPathJoin (which production uses). With os.DirFS, fs.Stat on those absolute paths fails with fs.ErrInvalid, so symlink target stats/directory detection aren’t actually exercised and the test can give false confidence.
	"go.uber.org/zap"

	"github.com/caddyserver/caddy/v2"
)

modules/caddyhttp/fileserver/browsetplcontext_test.go:148

  • Using os.DirFS here means symlink target stats will fail (directoryListing uses SanitizedPathJoin(root, ...) which yields absolute paths). Switch to the same absolute-path fs.FS style as production (internal/filesystems.OsFS) and read entries by opening the actual directory path.
	fileSystem := os.DirFS(dir)
	entries, err := fileSystem.(fs.ReadDirFS).ReadDir(".")
	if err != nil {
		t.Fatal(err)
	}

modules/caddyhttp/fileserver/browsetplcontext_bench_test.go:31

  • The benchmarks should use the same absolute-path fs.FS semantics as production (SanitizedPathJoin returns OS paths under root). Add internal/filesystems so readBenchDirEntries can return an fs.FS that accepts those paths; otherwise symlink-target fs.Stat calls can fail early with fs.ErrInvalid on os.DirFS and skew results.
	"go.uber.org/zap"

	"github.com/caddyserver/caddy/v2"
)

modules/caddyhttp/fileserver/browsetplcontext_bench_test.go:85

  • os.DirFS constrains Stat/Open to relative paths, but directoryListing builds absolute OS paths via SanitizedPathJoin(root, ...). That mismatch can make symlink-target stats fail with fs.ErrInvalid (and avoid real syscalls), skewing the directoryListing benchmarks. Consider using internal/filesystems.OsFS and opening dir by its full path.
	fileSystem := os.DirFS(dir)
	f, err := fileSystem.Open(".")
	if err != nil {
		tb.Fatal(err)
	}
	defer f.Close()

	entries, err := f.(fs.ReadDirFile).ReadDir(-1)
	if err != nil {
		tb.Fatal(err)
	}
	return fileSystem, entries

Copilot AI review requested due to automatic review settings July 26, 2026 10:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (3)

modules/caddyhttp/fileserver/browsetplcontext.go:351

  • These lines also have leading spaces before tabs (not gofmt-formatted). Please gofmt the file so indentation is consistent.
 	if l.Sort == sortByName || l.Sort == sortByNameDirFirst || l.Sort == sortBySize {
 		for i := range l.Items {
 			l.Items[i].nameLower = strings.ToLower(l.Items[i].Name)
 		}
	}

modules/caddyhttp/fileserver/browsetplcontext.go:156

  • The *Old implementations (directoryListingOld/applySortAndLimitOld and the old comparator types) are currently in non-test code, which means they’ll ship in production builds and require //nolint directives. Consider moving the old implementations into *_test.go (still in package fileserver) so benchmarks/parity tests can use them without adding dead code to the binary.
// directoryListingOld is the previous implementation of directoryListing, kept
// temporarily so its performance can be compared against directoryListing via
// benchmarks (see browsetplcontext_bench_test.go). It is unused in production
// code and should be deleted, along with its benchmark and parity test, once
// the new implementation has been merged and validated.

modules/caddyhttp/fileserver/browse.go:340

  • Since isSymlinkTargetDir is now only needed by directoryListingOld for benchmarks/parity tests, consider moving/removing it along with the other Old code so this production file doesn’t need a //nolint:unused directive.
// isSymlinkTargetDir returns true if f's symbolic link target
// is a directory.
//
//nolint:unused // only called from directoryListingOld, kept temporarily for benchmark comparison; see browsetplcontext_bench_test.go
func (fsrv *FileServer) isSymlinkTargetDir(fileSystem fs.FS, f fs.FileInfo, root, urlPath string) bool {

Copilot AI review requested due to automatic review settings July 26, 2026 10:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 6 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

modules/caddyhttp/fileserver/browsetplcontext_test.go:148

  • Using os.DirFS(dir) here makes file paths produced by caddyhttp.SanitizedPathJoin(root, urlPath+name) incompatible with fs.Stat and os.Readlink calls inside directoryListing/directoryListingOld (they produce absolute OS paths, but os.DirFS expects paths relative to dir). As a result, symlink target stats (dir vs file, target size) and RevealSymlinks behavior are not actually exercised by this parity test.
	fileSystem := filesystems.OsFS{}
	entries, err := fileSystem.ReadDir(dir)
	if err != nil {
		t.Fatal(err)
	}

modules/caddyhttp/fileserver/browsetplcontext_bench_test.go:86

  • readBenchDirEntries uses os.DirFS(dir), but the production fileserver uses a filesystem that operates on OS paths (see caddyhttp.SanitizedPathJoin returning filepath.Join(root, relPath)). With os.DirFS, the absolute paths generated for symlink stats (and os.Readlink) won't work, so the benchmarks don't measure the real stat/readlink behavior or the claimed reduction of duplicate stats for symlinks.

	fileSystem := filesystems.OsFS{}
	f, err := fileSystem.Open(dir)
	if err != nil {
		tb.Fatal(err)
	}
	defer f.Close()

	entries, err := f.(fs.ReadDirFile).ReadDir(-1)
	if err != nil {
		tb.Fatal(err)
	}
	return fileSystem, entries

Copilot AI review requested due to automatic review settings July 26, 2026 10:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 6 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

modules/caddyhttp/fileserver/browsetplcontext.go:351

  • applySortAndLimit precomputes nameLower for every item when sorting by size, but bySize only needs nameLower for directory-vs-directory comparisons. On large listings with few directories, this does avoidable O(n) allocations/work. Consider computing nameLower for all items only for name-based sorts, and only for directories when sorting by size.
	if l.Sort == sortByName || l.Sort == sortByNameDirFirst || l.Sort == sortBySize {
		for i := range l.Items {
			l.Items[i].nameLower = strings.ToLower(l.Items[i].Name)
		}
	}

modules/caddyhttp/fileserver/browsetplcontext.go:156

  • directoryListingOld/applySortAndLimitOld and the *Old comparator types are kept in non-test files, so they ship in production builds and require nolint suppressions. If these are only for parity tests/benchmarks, consider moving them (and isSymlinkTargetDir, if needed) into a _test.go file so they don’t increase shipped code size/surface area.
// directoryListingOld is the previous implementation of directoryListing, kept
// temporarily so its performance can be compared against directoryListing via
// benchmarks (see browsetplcontext_bench_test.go). It is unused in production
// code and should be deleted, along with its benchmark and parity test, once
// the new implementation has been merged and validated.

@firefart

Copy link
Copy Markdown
Contributor Author

Added the changes and updated the benchmark results in the description

@firefart
firefart requested a review from steadytao July 27, 2026 21:43

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional name normalisation and OsFS corrections address my earlier concerns. The remaining blocker is the old implementation being retained in production behind nolint; please remove that dead code and the unrelated test formatting churn.

@firefart

Copy link
Copy Markdown
Contributor Author

The conditional name normalisation and OsFS corrections address my earlier concerns. The remaining blocker is the old implementation being retained in production behind nolint; please remove that dead code and the unrelated test formatting churn.

Do you want me to also remove all temporary benchmarks?

@steadytao

Copy link
Copy Markdown
Member

The benchmarks for the new implementation can remain as useful regression measurements; there is no need to remove benchmarking entirely.

@steadytao

Copy link
Copy Markdown
Member

Just removing the old implementations and the old-vs-new parity/benchmark cases that depend on them would be fine.

Copilot AI review requested due to automatic review settings July 30, 2026 11:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 5 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

modules/caddyhttp/fileserver/browsetplcontext.go:236

  • The PR description says parity tests (TestDirectoryListingParity/TestApplySortAndLimitParity) and temporary Old implementations (directoryListingOld/applySortAndLimitOld/byNameOld/...) were added/kept, but those identifiers/tests don't exist anywhere in the repo. Either add the promised parity tests/Old implementations, or update the PR description so reviewers aren’t relying on non-existent comparisons.
	// Only compute lowercase names when the selected sort comparator needs it;
	// avoid O(n) work when sorting by time or when no sorting is requested.
	if l.Sort == sortByName || l.Sort == sortByNameDirFirst || l.Sort == sortBySize {
		for i := range l.Items {
			l.Items[i].nameLower = strings.ToLower(l.Items[i].Name)

Copilot AI review requested due to automatic review settings July 30, 2026 11:35
@firefart

Copy link
Copy Markdown
Contributor Author

@steadytao done

@firefart
firefart requested a review from steadytao July 30, 2026 11:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 5 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (3)

modules/caddyhttp/fileserver/browsetplcontext_bench_test.go:114

  • The benchmarks currently only exercise the new implementation, but the PR description claims Old/New versions plus parity tests exist (e.g. directoryListingOld/applySortAndLimitOld and Test*Parity). Either update the PR description or add the referenced old implementations/tests so reviewers can validate equivalence as described.
func BenchmarkDirectoryListing(b *testing.B) {
	for _, n := range []int{100, 1_000, 10_000, 50_000} {
		b.Run(fmt.Sprintf("entries=%d", n), func(b *testing.B) {
			benchmarkDirectoryListing(b, n, func(fsrv *FileServer, ctx context.Context, fileSystem fs.FS, entries []fs.DirEntry, root string) *browseTemplateContext {
				return fsrv.directoryListing(ctx, fileSystem, time.Time{}, entries, true, root, "/", caddy.NewReplacer())

modules/caddyhttp/fileserver/browsetplcontext_bench_test.go:59

  • Skipping the entire benchmark when symlink creation fails prevents running these benchmarks on platforms/configs where symlinks are disallowed (e.g. Windows without privileges). It would be better to continue and just omit the symlink entries, since the main performance characteristics (large file counts + sorting) can still be measured.
	if err := os.Symlink(target, filepath.Join(dir, "symlink-to-file")); err != nil {
		tb.Skipf("symlink not supported on this platform: %v", err)
	}

modules/caddyhttp/fileserver/browsetplcontext_bench_test.go:85

  • This unchecked type assertion will panic if the underlying fs.File does not implement fs.ReadDirFile. Even though OsFS currently returns an *os.File, guarding the assertion makes the benchmark more robust and fails with a clear message instead of a panic.
	entries, err := f.(fs.ReadDirFile).ReadDir(-1)
	if err != nil {
		tb.Fatal(err)
	}

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

@steadytao
steadytao merged commit 2adc763 into caddyserver:master Jul 31, 2026
26 checks passed
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.

fileserver - Really slow on big directories

4 participants