Clearing favicons from sqlite takes lots of time and cpu resources
Categories
(Toolkit :: Places, defect, P1)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox-esr140 | --- | unaffected |
| firefox146 | --- | unaffected |
| firefox147 | + | fixed |
| firefox148 | + | fixed |
People
(Reporter: smaug, Assigned: mak)
References
(Regression)
Details
(Keywords: regression, Whiteboard: [sng])
Attachments
(2 files)
|
48 bytes,
text/x-phabricator-request
|
Details | Review | |
|
48 bytes,
text/x-phabricator-request
|
phab-bot
:
approval-mozilla-beta+
|
Details | Review |
The following sqlite query uses tons of CPU time and makes the laptop fan scream for quite some time
DELETE FROM moz_icons_to_pages
WHERE (page_id, icon_id) IN (
SELECT page_id, icon_id
FROM moz_icons_to_pages ip
JOIN moz_icons i ON i.id = icon_id
JOIN moz_pages_w_icons pi ON pi.id = page_id
JOIN moz_places ON url_hash = page_url_hash
WHERE
last_visit_date BETWEEN
strftime('%s', ip.expire_ms / 1000, 'unixepoch', '+6 months', 'localtime', 'utc') * 1000000
AND strftime('%s', 'now', 'localtime', '-6 months', 'utc') * 1000000
I think it was added in bug 1959694.
| Assignee | ||
Updated•7 months ago
|
Updated•7 months ago
|
Comment 1•7 months ago
|
||
Set release status flags based on info from the regressing bug 1959694
| Assignee | ||
Comment 2•7 months ago
•
|
||
Ok, I see some entries in SlowSQL telemetry, so we can check after fixes this is not an issue anymore.
I see ~3000 users affected, both in 147 and 148.
| Reporter | ||
Comment 3•7 months ago
|
||
[Tracking Requested - why for this release]:
High CPU use for significant amount time.
| Assignee | ||
Comment 4•7 months ago
|
||
I think there is a bug in the SQLite query optimizer, for example I see that using an index on root it is returning the wrong number of results... and it's pretty slower. Skipping the root index seems to do the right thing and it's faster. Though I should first create a small use case to report the issue upstream.
In the meanwhile, could you please try running this query in the Browser Console? By not using the root index it should be significantly faster, it's like 6 times faster here.
(async function() {
let conn = await PlacesUtils.promiseDBConnection();
let time = performance.now();
let rows = await conn.execute(`SELECT count(*) FROM moz_icons_to_pages
WHERE (page_id, icon_id) IN (
SELECT page_id, icon_id
FROM moz_icons_to_pages ip
JOIN moz_pages_w_icons pi ON pi.id = page_id
JOIN moz_places ON url_hash = page_url_hash
WHERE
last_visit_date BETWEEN
strftime('%s', ip.expire_ms / 1000, 'unixepoch', '+6 months', 'localtime', 'utc') * 1000000
AND strftime('%s', 'now', 'localtime', '-6 months', 'utc') * 1000000
AND foreign_count = 0
AND NOT EXISTS (SELECT 1 FROM moz_icons WHERE id = icon_id AND root = 1)
LIMIT 50
)
`);
time = performance.now() - time;
console.log(`Results: ${rows[0].getResultByIndex(0)} in ${time}`);
})()
Updated•7 months ago
|
| Assignee | ||
Comment 7•7 months ago
|
||
SQLite is optimizing this expiration query wrongly, when using a
bloom filter and an automatic covering index on moz-icons.root.
In addition we're removing the ORDER BY clause as it's expensive. While
it makes sense to first expire older entries, in this case all the
entries are old, so we can save some power by not ordering them.
Also reduce the LIMIT to 50, for smaller I/O operations.
Comment 9•7 months ago
|
||
| bugherder | ||
| Assignee | ||
Comment 10•7 months ago
|
||
SQLite is optimizing this expiration query wrongly, when using a
bloom filter and an automatic covering index on moz-icons.root.
In addition we're removing the ORDER BY clause as it's expensive. While
it makes sense to first expire older entries, in this case all the
entries are old, so we can save some power by not ordering them.
Also reduce the LIMIT to 50, for smaller I/O operations.
Original Revision: https://phabricator.services.mozilla.com/D277312
Updated•7 months ago
|
Comment 11•7 months ago
|
||
firefox-beta Uplift Approval Request
- User impact if declined: perf problem causing cpu usage peak
- Code covered by automated testing: no
- Fix verified in Nightly: no
- Needs manual QE test: no
- Steps to reproduce for manual QE testing: While it would be nice, I fear it requires a db with a specific shape of the data, that QA may have difficulties with
- Risk associated with taking this patch: low
- Explanation of risk level: small SQL change, same results but avoiding an automatic index
- String changes made/needed: no
- Is Android affected?: no
Updated•7 months ago
|
Updated•7 months ago
|
Comment 12•7 months ago
|
||
| uplift | ||
Description
•