Skip to content

Slow Android navigation when encoding large content-blocker CSS - #62

Merged
tifroz merged 1 commit into
skiptools:mainfrom
tifroz:cosmetic-ad-blocker-css-encoding-optimization
Oct 27, 2026
Merged

tifroz merged 1 commit into
skiptools:mainfrom
tifroz:cosmetic-ad-blocker-css-encoding-optimization

Conversation

@tifroz

@tifroz tifroz commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

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 Skip JSONSerialization's per-character UTF-8 allocations. CSS content and injection guards remain unchanged. The Apple implementation and public APIs are unchanged.

Testing

  • Nine targeted Android instrumentation tests passed on the physical Samsung phone, with no failures or skips.
  • New coverage in Tests/SkipWebTests/AndroidCSSInjectionTests.swift checks 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.
  • Existing coverage in Tests/SkipWebTests/WebContentBlockerTests.swift checks domain, URL, and frame guards.
  • Benchmark measured the complete script-building call with 957,353 bytes of CSS and 8,192 rules, using five warm-up calls and 15 measured calls per run.
  • PR preparation verified the saved test log and matching production-source checksum. The branch was already current with upstream/main; no source changes or test reruns were needed during preparation. git diff --check passed.

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.

@cla-bot cla-bot Bot added the cla-signed label Oct 26, 2026
@tifroz
tifroz merged commit 30df519 into skiptools:main Oct 27, 2026
2 checks passed
@tifroz
tifroz deleted the cosmetic-ad-blocker-css-encoding-optimization branch October 27, 2026 03:59
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.

1 participant