Skip to content

fix(selectivity): reduce master-thread RAM usage#1209

Merged
KuznetsovRoman merged 1 commit intomasterfrom
TESTPLANE-903.restrict_selectivity_fs_parallelism
Feb 17, 2026
Merged

fix(selectivity): reduce master-thread RAM usage#1209
KuznetsovRoman merged 1 commit intomasterfrom
TESTPLANE-903.restrict_selectivity_fs_parallelism

Conversation

@KuznetsovRoman
Copy link
Member

No description provided.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 16, 2026

Open in StackBlitz

npm i https://pkg.pr.new/gemini-testing/testplane@1209

commit: d989eaf

Comment on lines 237 to 239
isCachedOnFs(source) ? getCachedSelectivityFile(CacheType.Asset, url) : source,
isCachedOnFs(sourceMaps)
? getCachedSelectivityFile(CacheType.Asset, sourceMapUrl as string)
Copy link
Member Author

Choose a reason for hiding this comment

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

These 2 should be added to "p-limit" at the same event loop iteration, so scripts would be processed one by one instead of "all fetch source first, then all fetch source maps"


const hashPromise = provider.calculateForFile(filePath);

await new Promise(setImmediate);
Copy link
Member Author

Choose a reason for hiding this comment

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

"p-limit" does not run passed functions instantly
We need to wait for the next event loop iteration

Comment on lines +197 to +198
shouldDisableBrowserSelectivity.cache.clear?.();
shouldDisableTestBySelectivity.cache.clear?.();
Copy link
Member Author

Choose a reason for hiding this comment

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

We dont need this cache after we started tests

startOffsets: number[],
sourceRoot: string,
): Promise<Set<string>> => {
): Set<string> => {
Copy link
Member Author

Choose a reason for hiding this comment

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

It became sync in 34690cd

export class HashProvider {
private static readonly _fileHashStore: Map<string, Promise<string>> = new Map();
private static readonly _patternHashStore: Map<string, Promise<string>> = new Map();
private static readonly _limited = pLimit(10);
Copy link
Member Author

Choose a reason for hiding this comment

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

Limiting "calculating hash" operation because node.js can buffer file contents (even if they are processed as stream) if cpu is busy (for example, by calculating md5)


this._processingTestPromises.push(
(async (): Promise<[Test, string] | null> => {
this._processingTestLimit(async () => {
Copy link
Member Author

Choose a reason for hiding this comment

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

limiting "checking if test changed" operation because it reads test dependencies file and file can be buffered

Comment on lines +20 to +21
// https://nodejs.org/api/cli.html#uv_threadpool_sizesize
const libUVLimited = pLimit((process.env.UV_THREADPOOL_SIZE && Number(process.env.UV_THREADPOOL_SIZE)) || 16);
Copy link
Member Author

Choose a reason for hiding this comment

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

There is no point in reading/writing more than "UV_THREADPOOL_SIZE" files at once, because libuv creates 4 threads
By default we set limit to 16, because node.js has its own queue and we want to make sure when libuv thread completes the task, it immediately takes the other one, prepared by node.js

@KuznetsovRoman KuznetsovRoman force-pushed the TESTPLANE-903.restrict_selectivity_fs_parallelism branch from 89e2c4e to d989eaf Compare February 17, 2026 13:10
@KuznetsovRoman KuznetsovRoman merged commit e2c4b66 into master Feb 17, 2026
7 checks passed
@KuznetsovRoman KuznetsovRoman deleted the TESTPLANE-903.restrict_selectivity_fs_parallelism branch February 17, 2026 13:15
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.

2 participants

Comments