Skip to content

[chore] Decrease standalone binary size#1858

Merged
Drarig29 merged 2 commits into
masterfrom
corentin.girard/patch-without-intl
Sep 24, 2025
Merged

[chore] Decrease standalone binary size#1858
Drarig29 merged 2 commits into
masterfrom
corentin.girard/patch-without-intl

Conversation

@Drarig29

@Drarig29 Drarig29 commented Sep 22, 2025

Copy link
Copy Markdown
Contributor

What and why?

This PR patches @yao-pkg/pkg and @yao-pkg/pkg-fetch to use precompiled binaries without Intl support with the --sea option.

See https://github.com/Drarig29/pkg-fetch#this-project-is-a-fork-used-by-datadogdatadog-ci-see-1858 for the big picture.

Before After
image image
Link Link

In the last version of datadog-ci we had standalone binaries based on Node.js 18, with a size of ~90MB. By moving to Node.js 22 without any optimization we would end up with ~125MB binaries.

With this PR, we have the best of both worlds: the upgrade to Node.js 22, and ~71MB binaries! 🎉

Before After
image image
Release v3.20.0 Release v3.21.0

How?

Fork @yao-pkg/pkg-fetch, prebuild Node.js binaries without Intl support and add patches in datadog-ci to use those prebuilt binaries.

We could write our own scripts to download the prebuilt binaries and generate the SEA binary without importing pkg or @yao-pkg/pkg at all, but this is more error-prone than tiny patches in the repo.

Review checklist

  • Feature or bugfix MUST have appropriate tests (unit, integration)

@Drarig29
Drarig29 force-pushed the corentin.girard/patch-without-intl branch from ab30f16 to 8321cfe Compare September 23, 2025 11:14
Base automatically changed from corentin.girard/SYNTH-13524/standalone-binary-sea to master September 23, 2025 12:48
@Drarig29
Drarig29 force-pushed the corentin.girard/patch-without-intl branch from 8321cfe to c6d435f Compare September 23, 2025 12:53
@Drarig29 Drarig29 added datadog-ci For PRs spanning multiple commands, and repo-wide changes guild-project Related to a project lead by the #datadog-ci-guild labels Sep 23, 2025
@Drarig29 Drarig29 changed the title Smaller binary size [chores] Decrease standalone binary size Sep 23, 2025
@Drarig29 Drarig29 changed the title [chores] Decrease standalone binary size [chore] Decrease standalone binary size Sep 23, 2025
@Drarig29
Drarig29 force-pushed the corentin.girard/patch-without-intl branch from 00982b0 to 1a75371 Compare September 23, 2025 14:24
@Drarig29
Drarig29 force-pushed the corentin.girard/patch-without-intl branch from 1a75371 to 60a5040 Compare September 23, 2025 14:33
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Sep 23, 2025

Copy link
Copy Markdown

⚠️ Tests

⚠️ Warnings

❄️ 1 New flaky test detected

cli fips git-metadata upload supports the --fips-ignore-error option from packages/datadog-ci/src/__tests__/cli.test.ts (Datadog) (✨ Fix with BitsAI)
Exceeded timeout of 5000 ms for a test.
Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout.

ℹ️ Info

🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 3483462 | Docs | Was this helpful? Give us feedback!

Comment on lines +62 to +66
+ "node-v22.19.0-linux-arm64": "bf0b13343f044104e935e8c9581c1c8bbf4f70185fc49ee49a63c83be95e2b93",
+ "node-v22.19.0-linux-x64": "f51476881e6af23347b4e8e0cc56e1aeffe6641e7523f2cac9601287ab3d00b4",
+ "node-v22.19.0-macos-arm64": "83b21eb4f79caa516ac7638fcbbbedd9dd357756549dd61f69ee7d40f2d95e63",
+ "node-v22.19.0-macos-x64": "fb493dbaced86bc65b19e04b5a325c89f470bc318720b0ab505a00cbb80ec039",
+ "node-v22.19.0-win-x64": "8440fe844868085dce1eb363b819c982f56f650e789fd04aa8213ce9968f07c4"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

switch (_c.label) {
case 0:
- url = "https://github.com/yao-pkg/pkg-fetch/releases/download/".concat(tag, "/").concat(name);
+ url = "https://github.com/Drarig29/pkg-fetch/releases/download/".concat(tag, "/").concat(name);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Point to the fork when downloading the binaries from release assets

}
function satisfyingNodeVersion(nodeRange) {
- var versions = Object.keys(patches_json_1.default)
+ var versions = ['v22.19.0']

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hardcode the version that was used to build our prebuilt binaries

{
"name": "@yao-pkg/pkg-fetch",
- "version": "3.5.24",
+ "version": "1.0.0",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

1.0.0 becomes 1.0, and it should point to the tag of the release we want to download assets from

Comment on lines +9 to +15
- if (argv.sea) {
- await (0, sea_1.default)(inputFin, {
- targets,
- signature: argv.signature,
- });
- return;
- }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The current implementation of the --sea option in @yao-pkg/pkg skips the downloading of prebuilt binaries ("targets") with @yao-pkg/pkg-fetch – and directly downloads an official Node.js binary (without pkg's patches).

This patch moves that code down, after fetching targets with @yao-pkg/pkg-fetch so that we can fetch the binaries from our fork, using the other yarn patch.

Comment on lines +41 to +43
+ if (target.fabricator) {
+ return target.fabricator.binaryPath;
+ }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Early return to use the fetched prebuilt binary instead of re-fetching an official Node.js binary.

Comment on lines +6 to +11
const IntlCollator = function () {
return {
// See https://nodejs.org/api/intl.html
compare: (a, b) => String(a).localeCompare(b),
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The only requirement after using --with-intl=none is that the Intl global object isn't available anymore and trying to access it would throw a ReferenceError, so we need to add a shim to replace it.

@Drarig29
Drarig29 marked this pull request as ready for review September 23, 2025 15:16
@Drarig29
Drarig29 requested a review from a team as a code owner September 23, 2025 15:16

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

LGTM 👍

@Drarig29
Drarig29 merged commit 1dece8f into master Sep 24, 2025
33 of 34 checks passed
@Drarig29
Drarig29 deleted the corentin.girard/patch-without-intl branch September 24, 2025 10:04
This was referenced Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

datadog-ci For PRs spanning multiple commands, and repo-wide changes guild-project Related to a project lead by the #datadog-ci-guild

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants