mirror of
https://github.com/horizon-rust/horizon.git
synced 2026-11-07 02:56:17 -10:00
Merge pull request #11757 from kacpherek/perf/render-api-tracking
an edit in game/ no longer rebuilds the renderer: dev rebuild 22.7 s -> 12.0 s
This commit is contained in:
3 files changed
+30
-4
No files matched your search
+15
@@ -82,6 +82,21 @@ libmimalloc-sys = { path = "third_party/libmimalloc-sys" }
|
||||
[profile.dev]
|
||||
debug = "line-tables-only"
|
||||
|
||||
# The native mod API is generated by a build script that parses every file of game/ with syn on
|
||||
# each gameplay edit; unoptimized that took ~6 s of every rebuild, optimized ~1.5 s.
|
||||
[profile.dev.package.horizon-mod-api-gen]
|
||||
opt-level = 3
|
||||
[profile.dev.package.syn]
|
||||
opt-level = 3
|
||||
[profile.dev.package.proc-macro2]
|
||||
opt-level = 3
|
||||
[profile.release.package.horizon-mod-api-gen]
|
||||
opt-level = 3
|
||||
[profile.release.package.syn]
|
||||
opt-level = 3
|
||||
[profile.release.package.proc-macro2]
|
||||
opt-level = 3
|
||||
|
||||
[profile.release]
|
||||
lto = "thin"
|
||||
codegen-units = 1
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::{collections::HashSet, fs, path::Path};
|
||||
/// Generate only this crate's files, tracking every source read by the generator.
|
||||
/// `root` is supplied at run time by the consuming crate's build script.
|
||||
pub fn generate(root: &Path, out_dir: &Path, target: Target) -> Result<(), String> {
|
||||
track(root)?;
|
||||
track(root, target)?;
|
||||
let generated = sources(root, super::FillMode::Require)?;
|
||||
let outputs = match target {
|
||||
Target::Render => vec![("native_render_generated.rs", generated.render)],
|
||||
@@ -35,7 +35,7 @@ pub fn generate(root: &Path, out_dir: &Path, target: Target) -> Result<(), Strin
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn track(root: &Path) -> Result<(), String> {
|
||||
pub(super) fn track(root: &Path, target: Target) -> Result<(), String> {
|
||||
fn directory(path: &Path, extension: &str, recursive: bool) -> Result<(), String> {
|
||||
// Track the directory as well: adding a helper source or fragment changes the inputs.
|
||||
println!("cargo:rerun-if-changed={}", path.display());
|
||||
@@ -53,7 +53,18 @@ pub(super) fn track(root: &Path) -> Result<(), String> {
|
||||
println!("cargo:rerun-if-changed={}", root.join(path).display());
|
||||
}
|
||||
directory(&root.join("tools/native-hook-fragments"), "json", false)?;
|
||||
directory(&root.join("crates/horizon-client/src/game"), "rs", true)?;
|
||||
match target {
|
||||
// The host API is made from every `impl Game` method under game/.
|
||||
Target::Client => directory(&root.join("crates/horizon-client/src/game"), "rs", true)?,
|
||||
// The render hooks read only native_hooks.rs (and their own functions, tracked below).
|
||||
// Tracking all of game/ here rebuilt the renderer, and horizon-client-lib above it, on
|
||||
// every gameplay edit.
|
||||
Target::Render => println!(
|
||||
"cargo:rerun-if-changed={}",
|
||||
root.join("crates/horizon-client/src/game/native_hooks.rs")
|
||||
.display()
|
||||
),
|
||||
}
|
||||
let catalog = serde_json::from_str(
|
||||
&fs::read_to_string(root.join("native-hooks.json")).map_err(|e| e.to_string())?,
|
||||
)
|
||||
|
||||
@@ -1159,7 +1159,7 @@ mod injection_tests;
|
||||
/// Generate a dispatch fixture without preventing xtask from filling placeholders.
|
||||
#[doc(hidden)]
|
||||
pub fn generate_test_hooks(root: &Path, out_dir: &Path) -> Result<(), String> {
|
||||
build::track(root)?;
|
||||
build::track(root, Target::Client)?;
|
||||
let code = sources(root, FillMode::Ignore)?.hooks;
|
||||
fs::write(out_dir.join("mod_api_generated.rs"), code).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user