From 29654133742fa6e0043fdac5c9ee63f095171f1c Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Tue, 31 Dec 2024 11:19:00 -0800 Subject: [PATCH] perf: build denort with `panic = "abort"` for releases (#27507) This PR changes CI to build denort with a separate, new build profile `release-slim` that disables unwinding and strips symbols. This reduces the size of denort by about 10% current denort: ``` FILE SIZE VM SIZE -------------- -------------- 58.1% 39.3Mi 57.9% 39.3Mi __TEXT,__text 31.5% 21.3Mi 31.4% 21.3Mi __TEXT,__const 2.5% 1.68Mi 2.5% 1.68Mi __DATA_CONST,__const 2.4% 1.62Mi 2.4% 1.62Mi __TEXT,__eh_frame 2.4% 1.60Mi 2.4% 1.60Mi __TEXT,__gcc_except_tab 0.9% 610Ki 0.9% 610Ki __TEXT,__cstring 0.8% 536Ki 0.8% 536Ki Code Signature 0.7% 507Ki 0.7% 507Ki __TEXT,__unwind_info 0.3% 207Ki 0.3% 207Ki Function Start Addresses 0.2% 165Ki 0.2% 165Ki __DATA,__data 0.0% 0 0.2% 153Ki __DATA,__bss 0.1% 51.0Ki 0.1% 51.0Ki Rebase Info 0.1% 45.3Ki 0.1% 45.3Ki __TEXT,__literals 0.0% 31.4Ki 0.1% 36.8Ki [15 Others] 0.0% 25.6Ki 0.0% 25.7Ki [__TEXT] 0.0% 19.3Ki 0.0% 20.2Ki [__DATA] 0.0% 8.11Ki 0.0% 8.11Ki Lazy Binding Info 0.0% 8 0.0% 8.08Ki [__LINKEDIT] 0.0% 6.84Ki 0.0% 6.84Ki Symbol Table 0.0% 5.55Ki 0.0% 5.55Ki String Table 0.0% 5.53Ki 0.0% 5.53Ki __TEXT,__ustring 100.0% 67.6Mi 100.0% 67.8Mi TOTAL ``` built with this PR: ``` FILE SIZE VM SIZE -------------- -------------- 59.6% 36.6Mi 59.5% 36.6Mi __TEXT,__text 34.6% 21.3Mi 34.5% 21.3Mi __TEXT,__const 2.7% 1.68Mi 2.7% 1.68Mi __DATA_CONST,__const 1.0% 610Ki 1.0% 610Ki __TEXT,__cstring 0.8% 487Ki 0.8% 487Ki Code Signature 0.3% 193Ki 0.3% 193Ki Function Start Addresses 0.3% 165Ki 0.3% 165Ki __DATA,__data 0.0% 0 0.2% 153Ki __DATA,__bss 0.2% 152Ki 0.2% 152Ki __TEXT,__unwind_info 0.1% 69.5Ki 0.1% 69.5Ki __TEXT,__eh_frame 0.1% 50.9Ki 0.1% 50.9Ki Rebase Info 0.1% 45.3Ki 0.1% 45.3Ki __TEXT,__literals 0.1% 34.1Ki 0.1% 39.5Ki [15 Others] 0.0% 19.3Ki 0.0% 20.2Ki [__DATA] 0.0% 19.6Ki 0.0% 19.7Ki [__TEXT] 0.0% 16.6Ki 0.0% 16.6Ki __TEXT,__gcc_except_tab 0.0% 8.09Ki 0.0% 8.09Ki Lazy Binding Info 0.0% 8 0.0% 7.69Ki [__LINKEDIT] 0.0% 6.83Ki 0.0% 6.83Ki Symbol Table 0.0% 5.77Ki 0.0% 5.77Ki [__DATA_CONST] 0.0% 5.53Ki 0.0% 5.53Ki __TEXT,__ustring 100.0% 61.4Mi 100.0% 61.6Mi TOTAL ``` A caveat is that this will increase release build times in CI since it requires building twice - once with unwinding and once without --- .github/workflows/ci.generate.ts | 30 +++++++++++++++++++++++------- .github/workflows/ci.yml | 25 ++++++++++++++++++------- Cargo.toml | 5 +++++ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.generate.ts b/.github/workflows/ci.generate.ts index d43d80d8bc..3cc559ec90 100755 --- a/.github/workflows/ci.generate.ts +++ b/.github/workflows/ci.generate.ts @@ -716,6 +716,19 @@ const ci = { "df -h", ].join("\n"), }, + { + name: "Build denort release", + if: [ + "matrix.job == 'test' &&", + "matrix.profile == 'release' &&", + "github.repository == 'denoland/deno'", + ].join("\n"), + run: [ + "df -h", + "cargo build --profile=release-slim --locked --bin denort", + "df -h", + ].join("\n"), + }, { // Run a minimal check to ensure that binary is not corrupted, regardless // of our build mode @@ -762,10 +775,11 @@ const ci = { "cd target/release", "zip -r deno-${{ matrix.arch }}-unknown-linux-gnu.zip deno", "shasum -a 256 deno-${{ matrix.arch }}-unknown-linux-gnu.zip > deno-${{ matrix.arch }}-unknown-linux-gnu.zip.sha256sum", - "strip denort", - "zip -r denort-${{ matrix.arch }}-unknown-linux-gnu.zip denort", - "shasum -a 256 denort-${{ matrix.arch }}-unknown-linux-gnu.zip > denort-${{ matrix.arch }}-unknown-linux-gnu.zip.sha256sum", "./deno types > lib.deno.d.ts", + "cd ../release-slim", + "zip -r ../release/denort-${{ matrix.arch }}-unknown-linux-gnu.zip denort", + "cd ../release", + "shasum -a 256 denort-${{ matrix.arch }}-unknown-linux-gnu.zip > denort-${{ matrix.arch }}-unknown-linux-gnu.zip.sha256sum", ].join("\n"), }, { @@ -790,8 +804,9 @@ const ci = { "cd target/release", "zip -r deno-${{ matrix.arch }}-apple-darwin.zip deno", "shasum -a 256 deno-${{ matrix.arch }}-apple-darwin.zip > deno-${{ matrix.arch }}-apple-darwin.zip.sha256sum", - "strip denort", - "zip -r denort-${{ matrix.arch }}-apple-darwin.zip denort", + "cd ../release-slim", + "zip -r ../release/denort-${{ matrix.arch }}-apple-darwin.zip denort", + "cd ../release", "shasum -a 256 denort-${{ matrix.arch }}-apple-darwin.zip > denort-${{ matrix.arch }}-apple-darwin.zip.sha256sum", ] .join("\n"), @@ -808,8 +823,9 @@ const ci = { run: [ "Compress-Archive -CompressionLevel Optimal -Force -Path target/release/deno.exe -DestinationPath target/release/deno-${{ matrix.arch }}-pc-windows-msvc.zip", "Get-FileHash target/release/deno-${{ matrix.arch }}-pc-windows-msvc.zip -Algorithm SHA256 | Format-List > target/release/deno-${{ matrix.arch }}-pc-windows-msvc.zip.sha256sum", - "Compress-Archive -CompressionLevel Optimal -Force -Path target/release/denort.exe -DestinationPath target/release/denort-${{ matrix.arch }}-pc-windows-msvc.zip", - "Get-FileHash target/release/denort-${{ matrix.arch }}-pc-windows-msvc.zip -Algorithm SHA256 | Format-List > target/release/denort-${{ matrix.arch }}-pc-windows-msvc.zip.sha256sum", + + "Compress-Archive -CompressionLevel Optimal -Force -Path target/release-slim/denort.exe -DestinationPath target/release/denort-${{ matrix.arch }}-pc-windows-msvc.zip", + "Get-FileHash target/release/denort${{ matrix.arch }}-pc-windows-msvc.zip -Algorithm SHA256 | Format-List > target/release/denort-${{ matrix.arch }}-pc-windows-msvc.zip.sha256sum", ].join("\n"), }, { diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc1aa89669..4fbaf82fcb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -419,6 +419,15 @@ jobs: df -h cargo build --release --locked --all-targets df -h + - name: Build denort release + if: |- + !(matrix.skip) && (matrix.job == 'test' && + matrix.profile == 'release' && + github.repository == 'denoland/deno') + run: |- + df -h + cargo build --profile=release-slim --locked --bin denort + df -h - name: Check deno binary if: '!(matrix.skip) && (matrix.job == ''test'')' run: 'target/${{ matrix.profile }}/deno eval "console.log(1+2)" | grep 3' @@ -448,10 +457,11 @@ jobs: cd target/release zip -r deno-${{ matrix.arch }}-unknown-linux-gnu.zip deno shasum -a 256 deno-${{ matrix.arch }}-unknown-linux-gnu.zip > deno-${{ matrix.arch }}-unknown-linux-gnu.zip.sha256sum - strip denort - zip -r denort-${{ matrix.arch }}-unknown-linux-gnu.zip denort - shasum -a 256 denort-${{ matrix.arch }}-unknown-linux-gnu.zip > denort-${{ matrix.arch }}-unknown-linux-gnu.zip.sha256sum ./deno types > lib.deno.d.ts + cd ../release-slim + zip -r ../release/denort-${{ matrix.arch }}-unknown-linux-gnu.zip denort + cd ../release + shasum -a 256 denort-${{ matrix.arch }}-unknown-linux-gnu.zip > denort-${{ matrix.arch }}-unknown-linux-gnu.zip.sha256sum - name: Pre-release (mac) if: |- !(matrix.skip) && (matrix.os == 'macos' && @@ -467,8 +477,9 @@ jobs: cd target/release zip -r deno-${{ matrix.arch }}-apple-darwin.zip deno shasum -a 256 deno-${{ matrix.arch }}-apple-darwin.zip > deno-${{ matrix.arch }}-apple-darwin.zip.sha256sum - strip denort - zip -r denort-${{ matrix.arch }}-apple-darwin.zip denort + cd ../release-slim + zip -r ../release/denort-${{ matrix.arch }}-apple-darwin.zip denort + cd ../release shasum -a 256 denort-${{ matrix.arch }}-apple-darwin.zip > denort-${{ matrix.arch }}-apple-darwin.zip.sha256sum - name: Pre-release (windows) if: |- @@ -480,8 +491,8 @@ jobs: run: |- Compress-Archive -CompressionLevel Optimal -Force -Path target/release/deno.exe -DestinationPath target/release/deno-${{ matrix.arch }}-pc-windows-msvc.zip Get-FileHash target/release/deno-${{ matrix.arch }}-pc-windows-msvc.zip -Algorithm SHA256 | Format-List > target/release/deno-${{ matrix.arch }}-pc-windows-msvc.zip.sha256sum - Compress-Archive -CompressionLevel Optimal -Force -Path target/release/denort.exe -DestinationPath target/release/denort-${{ matrix.arch }}-pc-windows-msvc.zip - Get-FileHash target/release/denort-${{ matrix.arch }}-pc-windows-msvc.zip -Algorithm SHA256 | Format-List > target/release/denort-${{ matrix.arch }}-pc-windows-msvc.zip.sha256sum + Compress-Archive -CompressionLevel Optimal -Force -Path target/release-slim/denort.exe -DestinationPath target/release/denort-${{ matrix.arch }}-pc-windows-msvc.zip + Get-FileHash target/release/denort${{ matrix.arch }}-pc-windows-msvc.zip -Algorithm SHA256 | Format-List > target/release/denort-${{ matrix.arch }}-pc-windows-msvc.zip.sha256sum - name: Upload canary to dl.deno.land if: |- !(matrix.skip) && (matrix.job == 'test' && diff --git a/Cargo.toml b/Cargo.toml index 1a7c04dbef..e4b9e0f496 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -251,6 +251,11 @@ incremental = true lto = true opt-level = 'z' # Optimize for size +[profile.release-slim] +inherits = "release" +panic = "abort" +strip = "symbols" + # Build release with debug symbols: cargo build --profile=release-with-debug [profile.release-with-debug] inherits = "release"