feat: rust performance and api improvements#2080
Conversation
…st-perf-improvements
Greptile SummaryThis PR refactors the Rust native module SDK into a proper Cargo workspace (
Confidence Score: 5/5Safe to merge; the lifecycle and concurrency concerns from previous rounds are addressed and the new code is well-tested. The two independent-task split eliminates the old publish/recv mutual blocking, teardown now always runs before failure propagation, and the task handles are properly awaited in the select!. Tests cover the concurrency properties directly. The remaining findings are style-level: a missing where bound on generated state-field initializers and a narrow gap in the pre-commit hook trigger condition. Neither affects runtime correctness. No files require special attention; the macro and runtime code are consistent with each other and with the documented examples. Important Files Changed
Sequence DiagramsequenceDiagram
participant Main
participant RunFn as "run()"
participant Builder
participant RecvTask
participant PubTask
participant Transport
Main->>RunFn: "run::<M,T>(transport)"
RunFn->>RunFn: "read JSON from stdin (topics + config)"
RunFn->>Builder: "Builder::new(topics, publish_tx)"
RunFn->>Builder: "M::build(&mut builder, config)"
Builder-->>RunFn: "module (Input/Output fields populated)"
RunFn->>RecvTask: "tokio::spawn recv loop"
RunFn->>PubTask: "tokio::spawn publish loop"
RunFn->>RunFn: "module.setup().await"
loop "module.handle() select! over inputs"
RecvTask->>Transport: "transport.recv().await"
Transport-->>RecvTask: "(channel, data)"
RecvTask->>RecvTask: "routes[channel].try_dispatch(data)"
RecvTask->>RunFn: "Input channel receives decoded message"
RunFn->>RunFn: "handle_field(msg).await"
RunFn->>PubTask: "Output::publish sends to publish_tx"
PubTask->>Transport: "transport.publish(topic, bytes)"
end
alt "ctrl-c OR handle() exits OR task panic"
RunFn->>RunFn: "module.teardown().await"
RunFn->>RunFn: "propagate_task_failure if panicked"
RunFn-->>Main: "Ok(()) or panic"
end
Reviews (8): Last reviewed commit: "Teardown even with error" | Re-trigger Greptile |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| - id: cargo-fmt | ||
| name: cargo fmt | ||
| entry: bash -c "cargo fmt --manifest-path native/rust/Cargo.toml --all --check && cargo fmt --manifest-path examples/native-modules/rust/Cargo.toml --check" | ||
| language: system | ||
| types: [rust] | ||
| pass_filenames: false |
There was a problem hiding this comment.
@Dreamsorcerer example of why I care about single path for CI and local dev envs for linting/code modification, think we should do what we discussed with modifying vs validating pre-commit hooks?
Co-authored-by: Paul Nechifor <paul@nechifor.net>
Problem
Rust module needs some performance improvements and the api could be better.
Closes DIM-XXX
Solution
New api (refer to native/rust/README.md for more docs):
dimos-module-macroscrate for message handling and boiler plate (no more select! or match, just write the handlers)Performance changes:
Tests:
Random:
dimos-moduleanddimos-module-macroscargo clippyandcargo fmtto precommit. In future should add CI testing.How to Test
cargo testpython3 rust_ping_pong.pyContributor License Agreement