Repository navigation
Slow Android navigation when encoding large content-blocker CSS - #62
Merged
tifroz merged 1 commit intoOct 27, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Building the content-blocker injection script for large CSS payloads is slow on Android during navigation. For 957 KB of CSS on a physical Samsung SM-S721U, the median script-building time dropped from 1,003 ms to 41 ms, a 24.5× speedup.
Use
org.json.JSONObject.quote(css)directly on Android to avoid SkipJSONSerialization's per-character UTF-8 allocations. CSS content and injection guards remain unchanged. The Apple implementation and public APIs are unchanged.Testing
Tests/SkipWebTests/AndroidCSSInjectionTests.swiftchecks escaping, Unicode, control characters, trimming and joining, empty input, and real WebView execution. The WebView test confirms unchanged CSS text, no script escape, and successful element hiding.Tests/SkipWebTests/WebContentBlockerTests.swiftchecks domain, URL, and frame guards.upstream/main; no source changes or test reruns were needed during preparation.git diff --checkpassed.Risks / Limitations
The benchmark covers script construction on one physical Android device using a debug instrumentation build. It does not measure total navigation time. The real WebView test requires an Android device or emulator and skips under Robolectric.