PHANTOM
🇮🇳 IN
Skip to content

[iOS] Improve cosmetic filtering performance with mutated elements on iOS #32060

Merged
StephenHeaps merged 1 commit intomasterfrom
privacy/ios-mutation-elements-perf
Nov 18, 2025
Merged

[iOS] Improve cosmetic filtering performance with mutated elements on iOS #32060
StephenHeaps merged 1 commit intomasterfrom
privacy/ios-mutation-elements-perf

Conversation

@StephenHeaps
Copy link
Collaborator

@StephenHeaps StephenHeaps commented Oct 28, 2025

iOS currently debounces sending selectors & classes added via mutations, so if a site mutates frequently it will delay sending the selectors to the adblock engine to determine if we should hide them. This PR updates it so we throttle instead of debounce, so they will be sent at most 200ms after detecting them via mutation observation.

Desktop's ShouldThrottleFetchNewClassIdsRules is similar to iOS's sendPendingSelectorsThrottled.

However, the difference is that desktop does this in ShouldThrottleFetchNewClassIdsRules:

if (fetchNewClassIdRulesTimeoutId) {
return true // The function has already scheduled and called later.
}

Which is a correct throttle. Where iOS currently does this in sendPendingSelectorsThrottled:

if (sendPendingSelectorsTimerId) {
// Each time this is called cancel the timer and allow a new one to start
window.clearTimeout(sendPendingSelectorsTimerId)
}

which is a debounce. This PR updates iOS to align with a proper throttle, instead of a debounce.

Resolves brave/brave-browser#48517

@StephenHeaps StephenHeaps self-assigned this Oct 28, 2025
@StephenHeaps StephenHeaps added CI/skip-android Do not run CI builds for Android CI/skip-windows-x64 Do not run CI builds for Windows x64 CI/skip-macos-arm64 Do not run CI builds for macOS arm64 CI/skip-teamcity labels Oct 28, 2025
@StephenHeaps StephenHeaps force-pushed the privacy/ios-mutation-elements-perf branch from 3225f50 to a656cf4 Compare October 28, 2025 16:49
@atuchin-m atuchin-m self-requested a review October 28, 2025 20:18
@StephenHeaps StephenHeaps force-pushed the privacy/ios-mutation-elements-perf branch from a656cf4 to 2686a0d Compare October 29, 2025 17:55
@StephenHeaps StephenHeaps marked this pull request as ready for review October 29, 2025 18:15
@StephenHeaps StephenHeaps requested a review from a team November 11, 2025 19:02
@StephenHeaps StephenHeaps merged commit 13b59c4 into master Nov 18, 2025
19 checks passed
@StephenHeaps StephenHeaps deleted the privacy/ios-mutation-elements-perf branch November 18, 2025 16:09
@github-actions github-actions bot added this to the 1.86.x - Nightly milestone Nov 18, 2025
@brave-builds
Copy link
Collaborator

Released in v1.86.90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/skip-android Do not run CI builds for Android CI/skip-macos-arm64 Do not run CI builds for macOS arm64 CI/skip-windows-x64 Do not run CI builds for Windows x64

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve cosmetic filtering performance for mutated elements on iOS

4 participants