perf(reference): overlap reference-source identity lookups in traversal order (#11585)

The reference-source reader made about nine serial filesystem calls per
directory. It now runs its read-only identity lookups ahead of their turn,
bounded to four running at once (libuv's default filesystem concurrency):
opening admissions of the next pending directories, metadata of the next
listed names, and closing admissions of directories already enumerated.
Results are applied in traversal order: policy and exclusion callbacks keep
their order, the first error in traversal order is returned, a failure a
started lookup observed is retained, and every started lookup settles before
the read returns. Running opening admissions are counted, so older siblings
buried by deeper levels cannot raise concurrency with tree depth.

Measured on macOS, Node 24.22.1: the 130,000-directory regression's
reference-source read 27.5 s -> 17.2 s; a 20,000-directory flat tree
2.1-2.3 s -> 1.2 s; an 8,641-file source tree 1.41 s -> 1.31 s.

Refs #11365
This commit is contained in:
morluto authored and GitHub committed 2026-11-16 07:57:51 +08:00
1 parent e3eb4c1749
commit 65f78edce5
5 files changed
+356 -82

No files matched your search

+10 -8
View File
@@ -31,20 +31,22 @@ export const isAborted = (signal?: AbortSignal): boolean =>
export const noFollowOpenSupported = (): boolean =>
Number.isSafeInteger(constants.O_NOFOLLOW) && constants.O_NOFOLLOW !== 0;
export const validateDirectory = async (
root: string,
rootIdentity: BigIntStats,
path: string,
signal?: AbortSignal,
): Promise<
/** A directory's identity admission: its metadata, or why it was refused. */
export type DirectoryValidation =
| { readonly ok: true; readonly stats: BigIntStats }
| {
readonly ok: false;
readonly code: ReferenceSourceFailureCode;
readonly message: string;
readonly localDiagnostic?: string;
}
> => {
};
export const validateDirectory = async (
root: string,
rootIdentity: BigIntStats,
path: string,
signal?: AbortSignal,
): Promise<DirectoryValidation> => {
if (isAborted(signal))
return {
ok: false,