Skip to content

docs: add worker threads and Node.js LTS guidance to performance best practices - #2473

Merged
bjohansebas merged 8 commits into
expressjs:mainfrom
GroophyLifefor:docs-perf
Aug 2, 2026
Merged

docs: add worker threads and Node.js LTS guidance to performance best practices#2473
bjohansebas merged 8 commits into
expressjs:mainfrom
GroophyLifefor:docs-perf

Conversation

@GroophyLifefor

Copy link
Copy Markdown
Member

Add Node.js 24 and worker threads guidance to performance best practices

Add two new sections to the production best practices: performance and reliability page:

  • Use Node.js 24 or newer (ops section): recommend running Express on Node.js 24+, which benchmarks show can be roughly 2x faster than Node.js 22 due to cumulative V8 improvements.
  • Use worker threads for CPU-intensive tasks (dev section): show how to offload CPU-bound work (image processing, crypto, large transforms) from the event loop using worker_threads, with a small code example and a note distinguishing it from clustering.

Fix CodeTabs import leaking into rendered content on .md pages

remark-code-tabs.mjs emits MDX constructs (an mdxjsEsm import for CodeTabs and a JSX <CodeTabs> wrapper) whenever it groups cjs/mjs code fences. The plugin was registered in the shared markdown processor, so it also ran on plain .md files — where mdast-util-to-hast serialized the injected import node as literal text, causing import CodeTabs from '@components/primitives/Tabs/CodeTabs.astro'; to appear in the rendered page (visible on /en/advanced/best-practice-performance).

Changes

  • src/plugins/remark-code-tabs.mjs: the plugin is now a no-op for non-MDX files (detected via the VFile path/extname). .md pages render cjs/mjs blocks as normal highlighted code; .mdx pages keep working tabs.
  • tests/unit/remark-code-tabs.test.mjs: added coverage for the .md no-op behavior and MDX detection.

Test plan

  • npm run test:unit — 52 tests pass
  • ESLint + Prettier clean
  • Verified /en/advanced/best-practice-performance no longer leaks the import (required clearing the stale .astro/ content cache)

Before

image

After

image

@GroophyLifefor
GroophyLifefor requested a review from a team as a code owner August 2, 2026 09:14
@netlify

netlify Bot commented Aug 2, 2026

Copy link
Copy Markdown

Deploy Preview for expressjscom-preview ready!

Name Link
🔨 Latest commit 1985c1b
🔍 Latest deploy log https://app.netlify.com/projects/expressjscom-preview/deploys/6a6f888f62870c00082e7490
😎 Deploy Preview https://deploy-preview-2473--expressjscom-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 97 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports
🤖 Make changes Run an agent on this branch

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

@krzysdz

krzysdz commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Fix CodeTabs import leaking into rendered content on .md pages

Maybe we should rename all .md files to .mdx? There are just 4 plain .md files in pages/en and a couple blog posts. Everything in docs and api is .mdx.
cc: @bjohansebas

@bjohansebas

Copy link
Copy Markdown
Member

Maybe we should rename all .md files to .mdx? There are just 4 plain .md files in pages/en and a couple blog posts. Everything in docs and api is .mdx.
cc: @bjohansebas

I thought I'd already done that, but apparently I hadn't. And yes, we should rename it to .mdx so all the plugins work correctly.

Comment thread src/content/pages/en/advanced/best-practice-performance.mdx
Comment thread src/content/pages/en/advanced/best-practice-performance.mdx Outdated
Data passed to a worker via workerData or postMessage is copied, not
shared; sharing requires transferring objects or SharedArrayBuffer.
Also remove a duplicated worker_threads link and a redundant cluster
cross-reference.
Frame the raw worker_threads snippet as an illustration and add a
worker pool example using piscina, since creating a worker per request
is expensive and the Node.js docs recommend pooling instead. Link
Node's "Don't Block the Event Loop" guide for further guidance.
@bjohansebas

Copy link
Copy Markdown
Member

@GroophyLifefor @krzysdz , could you take a look and see if there's anything that needs correcting?

Comment thread src/content/pages/en/advanced/best-practice-performance.mdx
@GroophyLifefor

Copy link
Copy Markdown
Member Author

I didn't see any problems, good job

@bjohansebas bjohansebas added the docs Issues/pr concerning content label Aug 2, 2026
@bjohansebas bjohansebas changed the title Add Node.js 24 and worker threads guidance to performance best practices docs: add worker threads and Node.js LTS guidance to performance best practices Aug 2, 2026
@bjohansebas
bjohansebas merged commit 9c58ced into expressjs:main Aug 2, 2026
26 checks passed
@bjohansebas

Copy link
Copy Markdown
Member

thanks @GroophyLifefor !

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

Every time an external package is suggested, I'm little concerned, but I see that piscina is developed by Node.js TSC members, so I guess it's trustworthy.


### Use the latest LTS version of Node.js

Running your app on a recent Node.js release is one of the easiest ways to improve performance. Each new version of Node.js ships with cumulative improvements to the V8 JavaScript engine and the runtime itself, so the same Express app can handle significantly more requests simply by upgrading. Benchmarks such as NodeSource's [Node.js Performance Report](https://nodesource.com/pages/content-node-performance-report-wb.html) show how much throughput can improve from one Node.js version to the next. For production, use the latest [LTS release](https://nodejs.org/en/about/previous-releases) of Node.js, and keep it up to date as new versions come out.

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.

Each new version of Node.js ships with cumulative improvements to the V8 JavaScript engine and the runtime itself, so the same Express app can handle significantly more requests simply by upgrading.

Upgrading what? The object is missing and the sentence reads weird. "runtime" and "Node.js" would be repetitions and "it" is a bit ambiguous (could refer to the app), so I don't have any suggestion how to improve it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Since it isn't a single sentence, it's connected to the part before the comma, and the part before the comma clearly refers to upgrading Node.js, I think it's clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Issues/pr concerning content

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants