Skip to content

perf: don't set process.title - #8453

Merged
sheremet-va merged 1 commit into
vitest-dev:mainfrom
sheremet-va:perf/dont-set-process-title
Aug 19, 2025
Merged

sheremet-va merged 1 commit into
vitest-dev:mainfrom
sheremet-va:perf/dont-set-process-title

Conversation

@sheremet-va

Copy link
Copy Markdown
Member

Description

process.title takes 10ms on my machine (MacBook Pro) and 20ms on @AriPerkkio's machine. We are considering removing this call to improve performance.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@netlify

netlify Bot commented Aug 19, 2025

Copy link
Copy Markdown

✅ Deploy Preview for vitest-dev ready!

Name Link
🔨 Latest commit 5597043
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/68a43650ef4ffc0008f83143
😎 Deploy Preview https://deploy-preview-8453--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@sheremet-va
sheremet-va requested a review from AriPerkkio August 19, 2025 08:41

@AriPerkkio AriPerkkio 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.

This was nice feature but maybe not worth the perf hit. Users can still do this in setupFiles I guess.

@AriPerkkio

Copy link
Copy Markdown
Member

Minimal repros without Vitest:

const startTime = performance.now();
process.title = "node (example)";
console.log(`${(performance.now() - startTime).toFixed(2)} ms`);
// 12-15ms, Apple M2 Air 16BG

Inside node:child_process, env var to control process.title setter for comparison:

import { fork } from "node:child_process";
import { fileURLToPath } from "node:url";

const SET_NAME = process.env.SET_NAME;
const isMainThread = process.send === undefined;

if (isMainThread) {
  const startTime = performance.now();
  const subprocess = fork(fileURLToPath(import.meta.url));
  subprocess.on("exit", () => console.log(`${(performance.now() - startTime).toFixed(2)} ms`));
} else {
  if (SET_NAME) {
    process.title = "node (example)";
  }
}
$  node ./example.mjs 
26.50 ms
$  node ./example.mjs 
27.05 ms
$  node ./example.mjs 
26.66 ms

$ SET_NAME=1 node ./example.mjs 
40.38 ms
$ SET_NAME=1 node ./example.mjs 
39.52 ms
$ SET_NAME=1 node ./example.mjs 
38.79 ms

Using --title has same perf hit, ~40ms with this one:

import { fork } from "node:child_process";
import { fileURLToPath } from "node:url";

const isMainThread = process.send === undefined;

if (isMainThread) {
  const startTime = performance.now();

  const subprocess = fork(fileURLToPath(import.meta.url), undefined, { execArgv: ["--title=node (example)"]});
  subprocess.on("exit", () => console.log(`${(performance.now() - startTime).toFixed(2)} ms`));
} else {
  // Child process running
}

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