WIP: perf: test regression, needs Arc<T>

This commit is contained in:
swaits committed 2025-10-14 09:48:14 -06:00
1 parent 89fbd26a47
commit 04d1c13122
6 files changed
+182 -1529

No files matched your search

+9 -8
View File
@@ -254,9 +254,9 @@ pub fn task(_attr: TokenStream, item: TokenStream) -> TokenStream {
));
}
let listener = listeners[#i]
.downcast_ref::<announcement::Listener<#ty>>()
.downcast_ref::<announcement::Listener<std::sync::Arc<#ty>>>()
.ok_or_else(|| {
format!("Type mismatch: expected Listener<{}> at index {}",
format!("Type mismatch: expected Listener<Arc<{}>> at index {}",
stringify!(#ty), #i)
})?;
listener.listen().await
@@ -267,7 +267,8 @@ pub fn task(_attr: TokenStream, item: TokenStream) -> TokenStream {
.collect();
// Generate parameter refs for the run call
let param_refs: Vec<_> = params.iter().map(|(name, _)| quote! { &#name }).collect();
// Dereference the Arc to get &T for the user's function
let param_refs: Vec<_> = params.iter().map(|(name, _)| quote! { &*#name }).collect();
// Generate the execute method body based on whether we have self and async/sync
let run_call = if has_self_receiver {
@@ -320,11 +321,11 @@ pub fn task(_attr: TokenStream, item: TokenStream) -> TokenStream {
// Wrap in Arc for sharing
let output_arc = std::sync::Arc::new(output);
// Announce the result
// Announce the result (announce the Arc, not a clone of the data)
let announcer_typed = announcer
.downcast::<announcement::Announcer<#output_type>>()
.downcast::<announcement::Announcer<std::sync::Arc<#output_type>>>()
.map_err(|_| "Type mismatch: announcer type does not match task output type")?;
let _ = announcer_typed.announce((*output_arc).clone());
let _ = announcer_typed.announce(std::sync::Arc::clone(&output_arc));
// Return Arc-wrapped output
Ok(output_arc as std::sync::Arc<dyn std::any::Any + Send + Sync>)
@@ -349,7 +350,7 @@ pub fn task(_attr: TokenStream, item: TokenStream) -> TokenStream {
}
fn create_announcement_erased() -> (Box<dyn std::any::Any + Send>, Box<dyn std::any::Any + Send>) {
let (announcer, announcement) = announcement::Announcement::<#output_type>::new();
let (announcer, announcement) = announcement::Announcement::<std::sync::Arc<#output_type>>::new();
(
Box::new(announcer) as Box<dyn std::any::Any + Send>,
Box::new(announcement) as Box<dyn std::any::Any + Send>,
@@ -358,7 +359,7 @@ pub fn task(_attr: TokenStream, item: TokenStream) -> TokenStream {
fn create_listener_erased(announcement: &dyn std::any::Any) -> Box<dyn std::any::Any + Send> {
let announcement = announcement
.downcast_ref::<announcement::Announcement<#output_type>>()
.downcast_ref::<announcement::Announcement<std::sync::Arc<#output_type>>>()
.expect("Type mismatch: announcement type does not match task output type");
Box::new(announcement.listener()) as Box<dyn std::any::Any + Send>
}