Closed Bug 752868 Opened 12 years ago Closed 12 years ago

Outdated locales aren't being removed from extensions.sqlite, causing bad performance

Categories

(Toolkit :: Add-ons Manager, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla15

People

(Reporter: jwkbugzilla, Assigned: Unfocused)

Details

(Keywords: perf, Whiteboard: [snappy])

Attachments

(1 file)

Populating the addons list got pretty bad in my development profile lately, taking more than 20 seconds for 23 add-ons. I started JavaScript Deobfuscator to figure out what's holding it - and it pointed to XPIDatabase._readLocaleStrings as the operation being executed. Turned out, my extensions.sqlite file was almost 50 MB large, vacuuming only brought it down to 25 MB. Here are the stats from it:

sqlite> select count(*) from addon;
23
sqlite> select count(*) from addon_locale;
162
sqlite> select count(*) from locale;
10271
sqlite> select count(*) from locale_strings;
651031

Creating the database from scratch brought the size down to 800 kB (merely 346 locales left), the list is being populated within a second.

That's a development profile with tons of extension installations daily, being used with Firefox nightlies. So I also checked my regular profile which is only used with stable Firefox releases (currently Firefox 12), to make sure that this wasn't some temporary nightly glitch fixed long ago. The database size there is 2 MB:

sqlite> select count(*) from addon;
19
sqlite> select count(*) from addon_locale;
126
sqlite> select count(*) from locale;
680
sqlite> select count(*) from locale_strings;
32814

The issue isn't quite as bad here but the number of locales still seems way off. Looks like removing old locales on update doesn't work, or at least not always.
Strange, we rely on sqlite triggers to clean up the other tables when we remove an entry for addon (even updates are just a remove/add at the moment): http://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/extensions/XPIProvider.jsm#4694

I wonder if the triggers aren't working in some way?
Whiteboard: [snappy]
Huh, the table locale_strings has no index, I bet adding one for locale_id would make a big difference to the speed here, regardless of whether we're accidentally leaving junk behind.
Two days later my extensions.sqlite is at 12 MB again - Adblock Plus has way too many strings. The triggers seem to work fine in general, e.g. addon_locale doesn't have any stale entries. It's only the trigger supposed to remove from locale table that isn't working. Running the following SQL statements fixes things:

> delete from locale where id not in (select locale_id from addon_locale) and id not in (select defaultLocale from addon);
> vacuum;

Note that locale_strings table is emptied automatically meaning that the corresponding trigger works. There is only some issue with the delete_addon_locale trigger.
I think locale_strings is *not* getting emptied properly also. For Adblock Plus, all the rows in locale_strings are associated with the default locale - that's removed from the locale table by the delete_addon trigger. If there were strings from another locale in there, those wouldn't be removed because the delete_addon_locale trigger is misbehaving (not sure why, yet).

Additionally, addAddonMetadata() seems to be adding locales to the DB at least twice, via insertLocale():
https://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/extensions/XPIProvider.jsm#5361
Not sure if that's related yet.
(In reply to Blair McBride (:Unfocused) from comment #4)
> Additionally, addAddonMetadata() seems to be adding locales to the DB at
> least twice, via insertLocale():
> https://mxr.mozilla.org/mozilla-central/source/toolkit/mozapps/extensions/
> XPIProvider.jsm#5361
> Not sure if that's related yet.

Oh, duh, it is directly related. The triggers are working fine, but they only delete rows with an ID matching rows deleted from addon_locale. Since the locale table has extra rows with IDs that reference rows in addon_locale that don't exist, those extra rows are what don't get removed.
Assignee: nobody → bmcbride
Status: NEW → ASSIGNED
A note: I've added the query from comment 3 to Extension Auto-Installer 1.2 (released it a few minutes ago). It will now remove unused locales every time an add-on is installed through it - things slow down way too soon otherwise.
Attached patch Patch v1Splinter Review
Yes, I'm kinda abusing DB_SCHEMA here - but revving that is a convenient way to clean the database.
Attachment #624695 - Flags: review?(dtownsend+bugmail)
(In reply to Blair McBride (:Unfocused) from comment #7)
> Created attachment 624695 [details] [diff] [review]
> Patch v1
> 
> Yes, I'm kinda abusing DB_SCHEMA here - but revving that is a convenient way
> to clean the database.

That's fine, but since we're revving the schema can you also add an index on locale_strings for locale_id.
Comment on attachment 624695 [details] [diff] [review]
Patch v1

The code that is here looks good but please add the index before landing.
Attachment #624695 - Flags: review?(dtownsend+bugmail) → review+
Oh, duh (again). Pushed with a new index for locale_strings:

https://hg.mozilla.org/integration/fx-team/rev/4ae03007e811
Target Milestone: --- → mozilla15
https://hg.mozilla.org/mozilla-central/rev/4ae03007e811
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: