Skip to content

Commit

Permalink
perf: enable "fat" LTO for production release (#7088)
Browse files Browse the repository at this point in the history
* perf: enable "fat" LTO for release

* chore: update comments

* chore: only affect prod release

* chore: only affect prod release
  • Loading branch information
chenjiahan authored Jul 9, 2024
1 parent 67c00aa commit 092a49a
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ jobs:
with:
target: ${{ matrix.array.target }}
runner: ${{ matrix.array.runner }}
profile: "release-prod"

release:
name: Release
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,8 @@ lto = "thin"
opt-level = 3
panic = "abort"
strip = true

[profile.release-prod]
inherits = "release"
# Performs “fat” LTO which attempts to perform optimizations across all crates within the dependency graph.
lto = "fat"
7 changes: 7 additions & 0 deletions crates/node_binding/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
"build:release:x64": "cross-env RUST_TARGET=x86_64-apple-darwin node scripts/build.js --release",
"build:release:linux": "cross-env RUST_TARGET=x86_64-unknown-linux-gnu node scripts/build.js --release",
"build:release:win": "cross-env RUST_TARGET=x86_64-pc-windows-msvc node scripts/build.js --release",
"build:release-prod:all": "run-p build:release-prod:arm64 build:release-prod:x64 build:release-prod:linux && pnpm move-binding",
"build:release-prod": "node scripts/build.js --release-prod",
"watch:release-prod": "node scripts/build.js --release-prod --watch",
"build:release-prod:arm64": "cross-env RUST_TARGET=aarch64-apple-darwin node scripts/build.js --release-prod",
"build:release-prod:x64": "cross-env RUST_TARGET=x86_64-apple-darwin node scripts/build.js --release-prod",
"build:release-prod:linux": "cross-env RUST_TARGET=x86_64-unknown-linux-gnu node scripts/build.js --release-prod",
"build:release-prod:win": "cross-env RUST_TARGET=x86_64-pc-windows-msvc node scripts/build.js --release-prod",
"move-binding": "node scripts/move-binding",
"test": "tsc -p tsconfig.type-test.json"
},
Expand Down
9 changes: 9 additions & 0 deletions crates/node_binding/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ const { spawn } = require("child_process");

const CARGO_SAFELY_EXIT_CODE = 0;

// Faster release for CI & canary with `thin` LTO
let release = process.argv.includes("--release");
// Slower release for production with `fat` LTO
let releaseProd = process.argv.includes("--release-prod");
let watch = process.argv.includes("--watch");

build().then((value) => {
// Regarding cargo's non-zero exit code as an error.
if (value !== CARGO_SAFELY_EXIT_CODE) {
Expand All @@ -30,6 +34,9 @@ async function build() {
if (release) {
args.push("--release");
}
if (releaseProd) {
args.push('--profile release-prod');
}
if (watch) {
args.push("--watch");
}
Expand All @@ -44,6 +51,8 @@ async function build() {
args.push("--features plugin");
}

console.log(`Run command: napi ${args.join(' ')}`);

let cp = spawn("napi", args, {
stdio: "inherit",
shell: true
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"lint:rs": "node ./scripts/check_rust_dependency.cjs",
"build:binding:debug": "pnpm --filter @rspack/binding run build:debug",
"build:binding:release": "pnpm --filter @rspack/binding run build:release",
"build:binding:release-prod": "pnpm --filter @rspack/binding run build:release-prod",
"prepare": "is-ci || husky",
"test:diff": "pnpm --filter \"@rspack/*\" test:diff",
"test:hot": "pnpm --filter \"@rspack/*\" test:hot",
Expand Down

2 comments on commit 092a49a

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Ran ecosystem CI: Open

suite result
modernjs ❌ failure
_selftest ✅ success
nx ✅ success
rspress ✅ success
rsbuild ✅ success
examples ✅ success

@rspack-bot
Copy link

Choose a reason for hiding this comment

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

📝 Benchmark detail: Open

Name Base (2024-07-09 f2bc023) Current Change
10000_development-mode + exec 2.18 s ± 17 ms 2.16 s ± 28 ms -0.71 %
10000_development-mode_hmr + exec 688 ms ± 7.5 ms 690 ms ± 8.6 ms +0.30 %
10000_production-mode + exec 2.81 s ± 26 ms 2.78 s ± 23 ms -0.84 %
arco-pro_development-mode + exec 1.91 s ± 55 ms 1.89 s ± 93 ms -0.93 %
arco-pro_development-mode_hmr + exec 433 ms ± 1.8 ms 434 ms ± 1.2 ms +0.08 %
arco-pro_production-mode + exec 3.46 s ± 90 ms 3.42 s ± 101 ms -1.21 %
threejs_development-mode_10x + exec 1.57 s ± 16 ms 1.58 s ± 14 ms +0.76 %
threejs_development-mode_10x_hmr + exec 795 ms ± 8.4 ms 798 ms ± 8.1 ms +0.43 %
threejs_production-mode_10x + exec 5.58 s ± 22 ms 5.61 s ± 33 ms +0.51 %

Please sign in to comment.