Skip to content

Don't rewrite it in Rust. Rewrite the 5% that's slow: profile your app, port the hot functions with your coding agent, prove they behave the same. Python, JS/TS, Ruby, Java, Kotlin, Go, PHP, C/C++, C#, R.

python: build ports without LTO, like the other languages

Milosz63c375e08ae1
diff --git a/src/backend.rs b/src/backend.rs
index aa07e77..a0d7c77 100644
--- a/src/backend.rs
+++ b/src/backend.rs
@@ -305,8 +305,9 @@ pub const CARGO_CONFIG: &str = "# Built for the machine that runs it: .fast/lib
[target.aarch64-apple-darwin]\nrustflags = [\"-C\", \"target-cpu=native\", \"-C\", \"link-arg=-undefined\", \"-C\", \"link-arg=dynamic_lookup\"]\n\n\
[target.x86_64-apple-darwin]\nrustflags = [\"-C\", \"target-cpu=native\", \"-C\", \"link-arg=-undefined\", \"-C\", \"link-arg=dynamic_lookup\"]\n";
-/// No LTO and the default codegen units: a port lives in one crate, so cross-crate inlining buys
-/// nothing measurable, while rebuilds after each edit get about 4x faster (4.1s to 1.1s).
+/// No LTO and the default codegen units: a port's hot loop lives in its own crate, so cross-crate
+/// inlining buys nothing measurable, while rebuilds after each edit get 4-9x faster (4.1s to 1.1s;
+/// a PyO3 port 3.5s to 0.37s, its run time within noise).
pub const RELEASE_PROFILE: &str = "[profile.release]\nopt-level = 3\nlto = false\n\n\
# A crate of its own, even inside another Cargo workspace.\n[workspace]\n";
diff --git a/src/python.rs b/src/python.rs
index 9d53d88..005f8ef 100644
--- a/src/python.rs
+++ b/src/python.rs
@@ -642,12 +642,11 @@ fn cargo_toml(port: &Port, numpy: bool) -> String {
"# Rust port of {id}, generated by fast-anything.\n\
[package]\nname = \"{ext}\"\nversion = \"0.1.0\"\nedition = \"2024\"\npublish = false\n\n\
[lib]\nname = \"{ext}\"\ncrate-type = [\"cdylib\"]\n\n\
- [dependencies]\npyo3 = {{ version = \"{PYO3}\", features = [\"extension-module\", \"abi3-py310\"] }}\n{numpy}\n\
- [profile.release]\nopt-level = 3\nlto = \"fat\"\ncodegen-units = 1\n\n\
- # A crate of its own, even inside another Cargo workspace.\n[workspace]\n",
+ [dependencies]\npyo3 = {{ version = \"{PYO3}\", features = [\"extension-module\", \"abi3-py310\"] }}\n{numpy}\n{profile}",
id = port.id,
ext = port.ext,
numpy = if numpy { format!("numpy = \"{NUMPY}\"\n") } else { String::new() },
+ profile = backend::RELEASE_PROFILE,
)
}