fluxa-core/Cargo.toml
KhooLy fdf91ceb19 perf(headless-engine): replace clone-and-diff dispatch with dirty tracking
Per the robustness plan's §9 (flagged as the single highest-leverage
perf change in the crate): headless_engine_dispatch_json used to clone
the entire EngineState before the reducer ran, clone it again after,
then StatePatch::diff did a deep PartialEq walk across all 16 domains
and cloned each changed one a third time — cost scaled with everything
the user has ever loaded (full catalogs, episode lists), not with what
the action actually touched.

Introduces Tracked<T> (src/headless_engine/state.rs): wraps each
EngineState domain field so any mutable access — a field write, a
whole-value replacement via DerefMut, a method call taking &mut —
flips a dirty bit automatically. Serialize/Deserialize delegate
straight to the wrapped value, so the wire format is byte-for-byte
unchanged (verified by the golden wire fixtures added in the prior
commit, which pass unmodified). EngineState::diff_dirty() replaces
StatePatch::diff(before, after): it clones only domains whose dirty
bit is set and clears it, so both the pre-dispatch full clone and the
post-dispatch PartialEq walk are gone entirely. The ~16 call sites that
did whole-domain replacement (`engine.state.detail = DetailState {
...}`) needed `*engine.state.detail = ...` instead — the compiler
catches any site the migration missed as a type error, so there's no
way for this rewrite to silently skip a domain the way a hand-added
mark_dirty() call could.

Also fixes headless_engine_snapshot_json, which used to serialize
while still holding the engines mutex; it now clones the state and
drops the lock before calling serde_json::to_string.

Adds benches/ (criterion, `--features bench` dev-only surface via a
new bench_targets re-export module mirroring the existing fuzz_targets
pattern): headless_engine_dispatch benches a NavigationRequested
dispatch against a 500-stream detail state (a domain the action
doesn't touch, so the win is directly visible), and stream_ranking
benches player_source_sidebar_plan_json grouping 500 streams. CI gets
a bench-check job compiling and smoke-running both (`--test`) without
paying for full timing runs on every push.
2026-07-07 14:46:52 +03:00

85 lines
1.8 KiB
TOML

[workspace]
members = ["fluxa-streaming-engine"]
exclude = ["fuzz"]
resolver = "2"
[workspace.dependencies]
dolby_vision = { version = "3.3.2", default-features = false }
fluxa_core = { path = ".", default-features = false }
jni = { version = "0.21" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
[profile.release]
opt-level = 3
lto = true
codegen-units = 1
strip = "debuginfo"
panic = "unwind"
[workspace.lints.rust]
unsafe_op_in_unsafe_fn = "warn"
[workspace.lints.clippy]
unwrap_used = "warn"
expect_used = "warn"
indexing_slicing = "warn"
panic = "warn"
[package]
name = "fluxa_core"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
[lints]
workspace = true
[[bin]]
name = "uniffi-bindgen"
path = "uniffi-bindgen.rs"
required-features = ["uniffi-cli"]
[features]
default = ["native"]
native = [
"full-api",
"dep:jni",
"dep:dolby_vision",
"uniffi-bindings",
]
desktop = ["full-api"]
full-api = []
streaming-shared = []
uniffi-bindings = ["dep:uniffi", "full-api"]
uniffi-cli = ["uniffi-bindings", "uniffi/cli"]
wasm = ["full-api", "dep:wasm-bindgen", "chrono/wasmbind"]
fuzzing = []
bench = []
[dependencies]
base64 = "0.22"
chrono = { version = "0.4.45", features = ["serde"] }
dolby_vision = { workspace = true, optional = true }
jni = { workspace = true, optional = true }
regex = "1"
serde = { workspace = true }
serde_json = { workspace = true }
uniffi = { version = "0.31.1", optional = true }
wasm-bindgen = { version = "0.2", optional = true }
web-time = "1"
[dev-dependencies]
criterion = { version = "0.5", default-features = false }
[[bench]]
name = "headless_engine_dispatch"
harness = false
required-features = ["bench"]
[[bench]]
name = "stream_ranking"
harness = false
required-features = ["bench"]