Commit 150f9cf
authored
perf: order startup functions in release builds (#36219)
## Summary
- generate an exact function-entry order from a first-pass release
binary on Linux x86-64/arm64 and macOS arm64
- relink the same revision with the generated order, without committing
revision-specific order artifacts
- verify that the final binary preserves symbol coverage and improves
ordering relative to the first-pass binary
## Technique
Release CI now uses two passes for the supported targets:
1. Build the normal, unstripped release executable and preserve it as
the baseline.
2. Run representative startup workloads three times each: empty
JavaScript, cached TypeScript, an active timer, `deno serve`, `deno
test`, `node:crypto`, and `deno fmt`.
3. Trap the first execution of each function entry and restore its
original instruction. Linux uses `INT3` on x86-64 or `BRK` on arm64 with
`memfd` RX/RW aliases; macOS uses `BRK` with shared-memory RX/RW
aliases. Both arm64 tracers synchronize the instruction cache before
resuming. A small runner suspends the generator while workloads execute
so the generator's own V8 threads do not contaminate the trace.
4. Resolve traced addresses to linker-visible symbols and relink with
LLD's `--symbol-ordering-file` on Linux or Apple's `-order_file` on
macOS.
5. Compare the first-pass and final binaries. The verifier requires high
symbol coverage and rejects regressions, while allowing an already
well-ordered baseline to remain unchanged.
Generating the order from the same binary that consumes it is important
because Rust symbol hashes, outlined functions, and layout change across
revisions. The generated order and verification report are uploaded as
short-lived CI artifacts rather than checked into the repository.
## Results
Release builds from the investigation:
| Idle workload | Baseline | Page order | Exact function order |
| --- | ---: | ---: | ---: |
| Linux, no timers | 47.15 MiB | 34.63 MiB | **28.80 MiB** |
| Linux, timer active | 53.77 MiB | 40.14 MiB | **33.58 MiB** |
The exact Linux order saves 18.34 MiB without timers and 20.19 MiB with
a timer versus the unordered release build. It also saves another
5.82-6.57 MiB over page-granularity ordering by reducing the order from
72,876 symbols to 22,963 startup functions.
| Target | Ordered symbols | Timer-free RSS delta | Empty JS startup
delta | Cached TypeScript startup delta |
| --- | ---: | ---: | ---: | ---: |
| Linux x86-64 | 22,963 | **-18,784 KiB** | **-1.897 ms** | **-2.009
ms** |
| macOS arm64 | 46,869 | **-10,960 KiB** | **-1.052 ms** | **-1.078 ms**
|
Fresh macOS orders independently reproduced roughly 11.1 MiB RSS savings
after source changes, while stale or symbol-remapped orders lost a
substantial part of the benefit. This is why the workflow regenerates
the order for every release build.
Linux arm64 uses the same exact-entry workload and LLD ordering policy.
Its native tracer path was validated separately below; a release RSS
figure is intentionally omitted until measured from the full CI-built
binary.
## Validation
- `./tools/format.js`
- `./tools/lint.js`
- type-check all startup-order TypeScript tools with the local Deno
build
- compile both native tracers with `-Wall -Wextra -Werror`
- run the Linux arm64 tracer in a native container through its
production `memfd` RX/RW aliases, including 20 iterations of a 32-thread
simultaneous-entry race
- run the complete Linux arm64 generator/runner/tracer pipeline across
all seven workload categories with three repeats and zero unresolved
trace addresses
- generate fresh macOS and Linux traces and confirm every traced address
resolves to a symbol
- run the relative verifier against unordered, ordered, and
already-ordered control binaries on both platforms1 parent 9dcb61d commit 150f9cf
10 files changed
Lines changed: 3070 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1876 | 1876 | | |
1877 | 1877 | | |
1878 | 1878 | | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
1879 | 1918 | | |
1880 | 1919 | | |
1881 | 1920 | | |
| |||
4392 | 4431 | | |
4393 | 4432 | | |
4394 | 4433 | | |
| 4434 | + | |
| 4435 | + | |
| 4436 | + | |
| 4437 | + | |
| 4438 | + | |
| 4439 | + | |
| 4440 | + | |
| 4441 | + | |
| 4442 | + | |
| 4443 | + | |
| 4444 | + | |
| 4445 | + | |
| 4446 | + | |
| 4447 | + | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
| 4451 | + | |
| 4452 | + | |
| 4453 | + | |
| 4454 | + | |
| 4455 | + | |
| 4456 | + | |
| 4457 | + | |
| 4458 | + | |
| 4459 | + | |
| 4460 | + | |
| 4461 | + | |
| 4462 | + | |
| 4463 | + | |
| 4464 | + | |
| 4465 | + | |
| 4466 | + | |
| 4467 | + | |
| 4468 | + | |
| 4469 | + | |
| 4470 | + | |
4395 | 4471 | | |
4396 | 4472 | | |
4397 | 4473 | | |
| |||
6443 | 6519 | | |
6444 | 6520 | | |
6445 | 6521 | | |
| 6522 | + | |
| 6523 | + | |
| 6524 | + | |
| 6525 | + | |
| 6526 | + | |
| 6527 | + | |
| 6528 | + | |
| 6529 | + | |
| 6530 | + | |
| 6531 | + | |
| 6532 | + | |
| 6533 | + | |
| 6534 | + | |
| 6535 | + | |
| 6536 | + | |
| 6537 | + | |
| 6538 | + | |
| 6539 | + | |
| 6540 | + | |
| 6541 | + | |
| 6542 | + | |
| 6543 | + | |
| 6544 | + | |
| 6545 | + | |
| 6546 | + | |
| 6547 | + | |
| 6548 | + | |
| 6549 | + | |
| 6550 | + | |
| 6551 | + | |
| 6552 | + | |
| 6553 | + | |
| 6554 | + | |
| 6555 | + | |
| 6556 | + | |
| 6557 | + | |
| 6558 | + | |
| 6559 | + | |
| 6560 | + | |
| 6561 | + | |
6446 | 6562 | | |
6447 | 6563 | | |
6448 | 6564 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
602 | 602 | | |
603 | 603 | | |
604 | 604 | | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
605 | 614 | | |
606 | 615 | | |
607 | 616 | | |
| |||
899 | 908 | | |
900 | 909 | | |
901 | 910 | | |
| 911 | + | |
| 912 | + | |
902 | 913 | | |
903 | 914 | | |
904 | 915 | | |
| |||
936 | 947 | | |
937 | 948 | | |
938 | 949 | | |
939 | | - | |
| 950 | + | |
940 | 951 | | |
941 | 952 | | |
942 | 953 | | |
943 | 954 | | |
944 | 955 | | |
945 | 956 | | |
946 | 957 | | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
947 | 1017 | | |
948 | 1018 | | |
949 | 1019 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
431 | 432 | | |
432 | 433 | | |
433 | 434 | | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
434 | 538 | | |
435 | 539 | | |
436 | 540 | | |
| |||
457 | 561 | | |
458 | 562 | | |
459 | 563 | | |
| 564 | + | |
460 | 565 | | |
461 | 566 | | |
462 | 567 | | |
| |||
0 commit comments