turborepo
66c2f555 - Memory: Use `triomphe::Arc` for `SharedReference` (#8622)

Commit
1 year ago
Memory: Use `triomphe::Arc` for `SharedReference` (#8622) ### Description This eliminates the unused weakref count in `std::sync::Arc`, saving 64 bits per unique `SharedReference`. I noticed there's additional potential optimizations we could do here too (not included in this PR), of increasing levels of difficulty: - We can deduplicate `ValueTypeId` by moving it inside the `Arc`. - We can build a mapping of `std::any::TypeId` to `ValueTypeId`, and avoid storing the `ValueTypeId` entirely. - We can deduplicate the fat pointer's layout metadata by also storing it inside the `Arc` using the nightly `ptr_metadata` feature, similar to `triomphe::ThinArc` (but that only works for slices of non-dst elements, presumably because they don't want to depend on nightly). ### Testing Instructions Using dhat for measuring the max heap size (vercel/next.js/67166)... Do a release build ``` PACK_NEXT_COMPRESS=objcopy-zstd pnpm pack-next --release --features __internal_dhat-heap ``` Start the dev server in shadcn-ui, and try to load the homepage: ``` pnpm i pnpm --filter=www dev --turbo curl http://localhost:3003/ ``` After curl exits, kill the dev server. ``` pkill -INT next-server ``` **Before (2 Runs):** ``` [dhat]: Teardown profiler dhat: Total: 3,106,545,900 bytes in 20,113,580 blocks dhat: At t-gmax: 731,860,693 bytes in 4,924,028 blocks dhat: At t-end: 731,860,693 bytes in 4,924,028 blocks ``` ``` [dhat]: Teardown profiler dhat: Total: 3,108,036,858 bytes in 20,111,694 blocks dhat: At t-gmax: 730,059,664 bytes in 4,923,002 blocks dhat: At t-end: 730,059,536 bytes in 4,923,001 blocks ``` **After (2 Runs):** ``` [dhat]: Teardown profiler dhat: Total: 3,093,298,170 bytes in 20,127,818 blocks dhat: At t-gmax: 727,258,939 bytes in 4,923,863 blocks dhat: At t-end: 727,155,146 bytes in 4,923,901 blocks ``` ``` [dhat]: Teardown profiler dhat: Total: 3,102,661,690 bytes in 20,124,408 blocks dhat: At t-gmax: 728,190,876 bytes in 4,924,856 blocks dhat: At t-end: 728,124,976 bytes in 4,924,236 blocks ``` This is [a 0.4426% reduction](https://www.wolframalpha.com/input?i=Percent+change+from+%28731%2C860%2C693%2B730%2C059%2C664%29%2F2+to+%28727%2C258%2C939%2B728%2C190%2C876%29%2F2).
Author
bgw bgw
Parents
Loading