Micro-optimization for string format#95774
Conversation
I get this is a bit of a silly change in some ways. It isn't going to have some massive impact. But using dhat I got these stats on a smallish sample nextjs project ┌────────────────────────┬─────────────────────┬──────────────┬────────────────────┐ │ metric │ A (parse.rs change) │ B (baseline) │ delta │ ├────────────────────────┼─────────────────────┼──────────────┼────────────────────┤ │ total bytes allocated │ 438.4 MiB │ 442.6 MiB │ -4.3 MiB (-0.94%) │ ├────────────────────────┼─────────────────────┼──────────────┼────────────────────┤ │ total allocation count │ 1,672,688 │ 1,872,347 │ -199,659 (-10.66%) │ └────────────────────────┴─────────────────────┴──────────────┴────────────────────┘ Eliminating ~200k allocations from this small change just felt worth it.
Tests PassedCommit: a23f63d |
Stats from current PR🟢 1 improvement
📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📝 Changed Files (21 files)Files with changes:
View diffsapp-page-exp..ntime.dev.jsfailed to diffapp-page-exp..time.prod.jsfailed to diffapp-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsfailed to diffapp-page-tur..ntime.dev.jsfailed to diffapp-page-tur..time.prod.jsfailed to diffapp-page.runtime.dev.jsfailed to diffapp-page.runtime.prod.jsfailed to diffapp-route-ex..ntime.dev.jsDiff too large to display app-route-ex..time.prod.jsDiff too large to display app-route-tu..ntime.dev.jsDiff too large to display app-route-tu..time.prod.jsDiff too large to display app-route-tu..ntime.dev.jsDiff too large to display app-route-tu..time.prod.jsDiff too large to display app-route.runtime.dev.jsDiff too large to display app-route.ru..time.prod.jsDiff too large to display server.runtime.prod.jsDiff too large to display use-cache-pr..ntime.dev.jsDiff too large to display use-cache-pr..ntime.dev.jsDiff too large to display use-cache-pr..ntime.dev.jsDiff too large to display use-cache-pr..ntime.dev.jsDiff too large to display 📎 Tarball URLCommit: a23f63d |
| fn file_name_to_source(&self, f: &FileName) -> String { | ||
| match f { | ||
| FileName::Custom(s) => { | ||
| format!("{SOURCE_URL_PROTOCOL}///{s}") |
There was a problem hiding this comment.
Yes I was surprised by format not doing the optimal thing here as well. My understanding is the builtin only tries to find size of the constant values.
There was a problem hiding this comment.
yeah and SOURCE_URL_PROTOCOL is a constant rcstr which probably doesn't have a const len so it doesn't work well i guess? im not sure where it fails
perhaps using SOURCE_URL_PROTOCOL_STR directly would fix this
I get this is a bit of a silly change in some ways. It isn't going to have some massive impact. But using dhat I got these stats on a smallish sample nextjs project
Eliminating ~200k allocations from this small change just felt worth it.