Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

perf(error-tracking): avoid deep-cloning event properties in issue linking (#67849)

Catalin Irimie773be856072a
diff --git a/rust/cymbal/src/modes/processing/stages/linking/issue.rs b/rust/cymbal/src/modes/processing/stages/linking/issue.rs
index 8c907b379064..92d1fcb1f578 100644
--- a/rust/cymbal/src/modes/processing/stages/linking/issue.rs
+++ b/rust/cymbal/src/modes/processing/stages/linking/issue.rs
@@ -29,7 +29,7 @@ pub struct IssueLinker;
impl IssueLinker {
pub async fn fetch_or_create_issue(
- input: ExceptionProperties,
+ input: &ExceptionProperties,
ctx: Arc<AppContext>,
) -> Result<Issue, UnhandledError> {
// Extract name and description for the issue
@@ -67,14 +67,16 @@ impl ValueOperator for IssueLinker {
ISSUE_LINKER_OPERATOR
}
- async fn execute_value(
- &self,
- mut input: Self::Item,
- ctx: LinkingStage,
- ) -> OperatorResult<Self> {
+ async fn execute_value(&self, input: Self::Item, ctx: LinkingStage) -> OperatorResult<Self> {
let fingerprint = input.fingerprint.clone().unwrap();
let key = (input.team_id, fingerprint);
+ // Wrap the (large) event in an `Arc` so the cache-loader closures capture a cheap
+ // refcount bump instead of a full deep clone. The loaders only ever borrow the
+ // event, and they don't run at all on the warm-cache path, so on the hot path this
+ // is one `Arc` allocation and no `ExceptionProperties` copies.
+ let input = Arc::new(input);
+
// Two-layer cache: per-batch dedup wraps the cross-request `issue_id` cache.
// - Per-batch cache (this `try_get_with`): events with the same fingerprint in
// the same batch resolve the Issue exactly once. moka serializes concurrent
@@ -84,16 +86,21 @@ impl ValueOperator for IssueLinker {
// skips the expensive fingerprint JOIN on warm fingerprints.
// Status is always read fresh from PG inside the loader, so `IssueSuppression`
// and `maybe_reopen` never see stale state.
- let cloned_input = input.clone();
+ let input_for_load = input.clone();
let ctx_for_load = ctx.clone();
let issue: Issue = ctx
.batch_issue_cache
.try_get_with(key, async move {
- resolve_via_id_cache(cloned_input, &ctx_for_load).await
+ resolve_via_id_cache(input_for_load, &ctx_for_load).await
})
.await
.map_err(|e: Arc<UnhandledError>| UnhandledError::Other(e.to_string()))?;
+ // The only `Arc` clones were captured by this call's loader closures, which have
+ // all completed (or been dropped when moka deduped them), so we uniquely own the
+ // event again and can reclaim it to write back the resolved issue.
+ let mut input =
+ Arc::into_inner(input).expect("input Arc uniquely held after cache resolution");
input.issue_id = Some(issue.id);
input.issue = Some(issue);
@@ -108,7 +115,7 @@ impl ValueOperator for IssueLinker {
// - On cache hit we re-read by id (cheap PK lookup) and call `maybe_reopen` so
// suppression and reopen always see current PG state.
async fn resolve_via_id_cache(
- input: ExceptionProperties,
+ input: Arc<ExceptionProperties>,
ctx: &LinkingStage,
) -> Result<Issue, UnhandledError> {
let fingerprint = input.fingerprint.clone().unwrap();
@@ -125,7 +132,7 @@ async fn resolve_via_id_cache(
let issue_id: Uuid = ctx
.issue_cache
.try_get_with(key.clone(), async move {
- let issue = IssueLinker::fetch_or_create_issue(cloned_input, app_ctx).await?;
+ let issue = IssueLinker::fetch_or_create_issue(&cloned_input, app_ctx).await?;
let id = issue.id;
*slot.lock().expect("just_resolved mutex poisoned") = Some(issue);
Ok::<Uuid, UnhandledError>(id)
@@ -156,7 +163,7 @@ async fn resolve_via_id_cache(
None => {
// Cached id no longer exists in PG. Invalidate and run the slow path.
ctx.issue_cache.invalidate(&key).await;
- IssueLinker::fetch_or_create_issue(input, ctx.app_context.clone()).await
+ IssueLinker::fetch_or_create_issue(&input, ctx.app_context.clone()).await
}
}
}
@@ -216,7 +223,7 @@ async fn resolve_issue(
name: String,
description: String,
event_timestamp: DateTime<Utc>,
- event_properties: ExceptionProperties,
+ event_properties: &ExceptionProperties,
) -> Result<Issue, UnhandledError> {
let team_id = event_properties.team_id;
let fingerprint = event_properties
@@ -232,7 +239,7 @@ async fn resolve_issue(
if issue.maybe_reopen(&mut *conn).await? {
let first_seen_for_state = fingerprint_first_seen.unwrap_or(issue.created_at);
let assignment =
- process_assignment(&mut conn, &context.team_manager, &issue, &event_properties)
+ process_assignment(&mut conn, &context.team_manager, &issue, event_properties)
.await?;
send_fingerprint_issue_state(
context,
@@ -301,7 +308,7 @@ async fn resolve_issue(
if issue.maybe_reopen(&mut *conn).await? {
let first_seen_for_state = fingerprint_first_seen.unwrap_or(issue.created_at);
let assignment =
- process_assignment(&mut conn, &context.team_manager, &issue, &event_properties)
+ process_assignment(&mut conn, &context.team_manager, &issue, event_properties)
.await?;
send_fingerprint_issue_state(
context,
@@ -327,9 +334,9 @@ async fn resolve_issue(
} else {
metrics::counter!(ISSUE_CREATED).increment(1);
let assignment =
- process_assignment(&mut txn, &context.team_manager, &issue, &event_properties).await?;
+ process_assignment(&mut txn, &context.team_manager, &issue, event_properties).await?;
- let output_props = event_properties.clone().to_output(issue.id)?;
+ let output_props = event_properties.to_output(issue.id)?;
send_fingerprint_issue_state(
context,
&issue,