Ten years in the wrong regex lane
6 days ago
- #regex
- #iOS
- #performance
- AdGuard on iOS uses Safari's built-in content blocking mechanism, which relies on regular expressions (regexps) for URL matching.
- The initial regex conversion for AdGuard's URL patterns was suboptimal, leading to slow rule compilation and high CPU usage.
- A bug report revealed that the regex for '||' (start of URL) only matched a single subdomain level, unlike other AdGuard versions.
- Correcting the regex to match all subdomain levels significantly improved performance: 5.5x faster for Tracking Protection and 2.8x faster for Base filter compilation.
- The flawed initial testing methodology lacked precise measurement tools, relying on manual observation instead of profiling.
- Over ten years, the inefficient regex cost iOS users over 50 million hours of CPU time.
- The issue has been fixed, emphasizing the importance of proper testing and measurement in development.