Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions orch8-engine/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1522,13 +1522,19 @@ async fn emit_sla_alerts(
.map(|c| (c.instance_id, &c.block_id))
.collect();
let existing = ctx.storage.get_block_outputs_batch(&keys).await?;
let mut existing_ref = std::collections::HashSet::with_capacity(existing.len());
for k in existing.keys() {
existing_ref.insert((&k.0, &k.1));
}

// Performance: Sorting keys and using binary search avoids
// the allocation and hashing overhead of building a HashSet for
// exclusion checking on the execution hot path.
let mut existing_keys: Vec<(&InstanceId, &BlockId)> =
existing.keys().map(|(iid, bid)| (iid, bid)).collect();
existing_keys.sort_unstable();

for c in candidates {
if existing_ref.contains(&(&c.instance_id, &c.block_id)) {
if existing_keys
.binary_search(&(&c.instance_id, &c.block_id))
.is_ok()
{
continue;
}
// Persist the sentinel BEFORE emitting so a crash mid-emit cannot
Expand Down
15 changes: 14 additions & 1 deletion orch8-types/src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,20 @@ use uuid::Uuid;
/// Newtype wrappers prevent mixing up UUIDs at compile time.
/// Zero cost at runtime (transparent newtypes).

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, sqlx::Type, ToSchema)]
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Serialize,
Deserialize,
sqlx::Type,
ToSchema,
)]
#[sqlx(transparent)]
pub struct InstanceId(Uuid);

Expand Down
Loading