Files
sousa-gecko/dom/cache
Marcelo Camargo a9504964d2 Bug 2009295 - Optimize Cache Storage API match operations for O(log n) performance r=asuth,dom-worker-reviewers,hsingh
The Cache Storage API exhibited O(n) performance degradation as cache size grew,
taking ~0.79ms per cache.match() call with 15k entries. This was caused by three
separate bottlenecks:

1. URL string comparisons in SQL WHERE clause (not indexed)
2. Expensive LEFT JOIN + GROUP BY + COUNT() operations
3. Missing index on response_headers(entry_id, name)

This patch:
- Simplifies the SQL query to use hash-only WHERE clause with post-query URL verification
- Removes unnecessary JOIN/GROUP BY, checks vary headers separately when needed
- Adds composite index on response_headers(entry_id, name)
- Bumps schema version to 30 with migration

Performance improvement: 8x faster (0.79ms → 0.10ms per query with 15k entries)

Test case: https://ylngxt.csb.app/

r?asuth

Differential Revision: https://phabricator.services.mozilla.com/D278397
2026-07-14 04:14:59 +00:00
..