Skip to content

Hoist NLU classifier call out of body.links loop in link_mailto_placeholder#4802

Open
thunderkatz wants to merge 3 commits into
mainfrom
jkatzman/link-mailto-placeholder-hoist-nlu
Open

Hoist NLU classifier call out of body.links loop in link_mailto_placeholder#4802
thunderkatz wants to merge 3 commits into
mainfrom
jkatzman/link-mailto-placeholder-hoist-nlu

Conversation

@thunderkatz

Copy link
Copy Markdown
Contributor

Description

The classifier check on body.current_thread.text doesn't depend on link content, so nesting it inside any(body.links, ...) means the call site is reached once per qualifying link instead of once overall, and even though it's cached, it's not free. Hoisting the loop-independent check out of the loop saves that. Note that this requires splitting into two anys, since it was previously any(P or (Q and C), so now it's any(P) or (any(Q) and C) (the scheme check is duplicated in both loops but is significantly cheaper than the cached nlu call).

Associated samples

n/a - this is a no-op optimization

Associated hunts

n/a

Screenshot (insights)

n/a

…holder

The ml.nlu_classifier(body.current_thread.text) call doesn't depend on the
looped link, so nesting it inside any(body.links, ...) means the call site
is reached once per qualifying link instead of once overall, and the
memoized-call lookup does a full-string compare against current_thread.text
on every hit. Restructuring via any(P) or (any(Q) and C) == any(P or (Q and C))
(valid since C doesn't depend on the loop variable) moves the NLU check to a
single top-level any(), evaluated once and only when no @{domain} match
exists anywhere in the message.
@thunderkatz thunderkatz requested a review from a team July 6, 2026 14:37
@thunderkatz thunderkatz requested a review from a team as a code owner July 6, 2026 14:37
@github-actions github-actions Bot added the review-needed Indicates that a PR is waiting for review label Jul 6, 2026
@zoomequipd zoomequipd self-assigned this Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Shared Samples Sync - Action Required

This PR was not automatically synced to shared-samples because the author is not a member of the sublime-security organization.

To enable syncing, an organization member can comment /update-shared-samples on this PR.

Once triggered, the rules will be synced on the next scheduled run (every 10 minutes).

zoomequipd
zoomequipd previously approved these changes Jul 6, 2026

@zoomequipd zoomequipd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving without typical hunts due to performance concerns with running the hunts.

@thunderkatz has validated this change should have no efficacy impact.

@zoomequipd zoomequipd dismissed their stale review July 6, 2026 15:37

dismissed as per Ross

@thunderkatz thunderkatz enabled auto-merge July 6, 2026 17:02
@thunderkatz thunderkatz disabled auto-merge July 6, 2026 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants