Closed Bug 690903 Opened 14 years ago Closed 14 years ago

nsFormHistory should lazily initializes SQLite DB

Categories

(Toolkit :: Form Manager, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla10

People

(Reporter: mfinkle, Assigned: mounir)

References

Details

(Keywords: mobile, perf, Whiteboard: [mobilestartupshrink][inbound])

Attachments

(1 file, 5 obsolete files)

Currently, the SQLite DB is opened (and created if needed) during the component initialization. If we could make this lazy, we could move the SQLite blocking file process out of the startup path. This affects Firefox Mobile on phones with slow file systems quite a bit.
You would like to initialize the database the first time we try to access it instead of during startup, right? Is it better to push the task to a page load instead of app load? I really wonder what would be the worse in term of user experience.
OS: Linux → All
Hardware: x86 → All
Version: unspecified → Trunk
(In reply to Mounir Lamouri (:volkmar) (:mounir) from comment #1) > You would like to initialize the database the first time we try to access it > instead of during startup, right? Is it better to push the task to a page > load instead of app load? I really wonder what would be the worse in term of > user experience. Page load would still be too early for Fennec. We manually initialize form history in a page load now. I was hoping we could delay until some call actually needed to use the DB. This is kinda how login manager works. I have noticed that login manager and form history both use sync calls to SQLite during initialization, which hurts.
Doing the call asynchronously might require a lot of changes. If I understood correctly the numbers in the bug Vivien put in the blocking list, the thing that really hurts is the first run that creates the database? In that case, I guess lazily initializing the database should be okay given that except when creating them, this will be seamless. At least, seems worthy enough for me to try to write a patch.
Yes, creating the DB is a _big_ hit on some phones (I'm looking at you Galaxy S), but even opening the DB connection every time we load is a noticeable hit. And opening the DB right as the home page loads means we have some blocking I/O right when the user wants to start using the app.
Attached patch Patch v1 (obsolete) — Splinter Review
It seems to work but I didn't compute the speed gain. Though, on my dev phone (Galaxy S2), it's unlikely to be high.
Assignee: nobody → mounir
Status: NEW → ASSIGNED
Attachment #564408 - Flags: review?(dolske)
Flags: in-testsuite-
Whiteboard: mobilestartupshrink → [mobilestartupshrink][needs review]
To make sure this is clear, with this patch, nsFormHistory database will not be initialized on app load but the first time the user will select a text field in the content. On a fast phone it is barely visible. On a slow one, it will likely be visible. It's a trade-off to take or not...
Would it make any sense to convert all uses of: this.dbConnection to: this.DBConnection That might make it less painful to try to add a call to lazyDBInit()
Attached patch Patch v2 (obsolete) — Splinter Review
I'm ashamed... I should have think about that :(
Attachment #564408 - Attachment is obsolete: true
Attachment #564408 - Flags: review?(dolske)
Attachment #564497 - Flags: review?(dolske)
Attachment #564497 - Flags: feedback?(mark.finkle)
Comment on attachment 564497 [details] [diff] [review] Patch v2 > dbMigrateToVersion3 : function () { >+ this.lazyDbInit(); >+ Any reason you left this call here? I might have changed this.dbConnection -> this._dbConnection, but it's your call on that. Otherwise, looks good to me.
Attachment #564497 - Flags: feedback?(mark.finkle) → feedback+
Attached patch Patch v2.1 (obsolete) — Splinter Review
f=mfinkle Renaming dbConnection to _dbConnection. Removing the call I forgot to remove. Thanks for those advices, I believe it's quite obvious I'm not a JS hacker :)
Attachment #564497 - Attachment is obsolete: true
Attachment #564497 - Flags: review?(dolske)
Attachment #564529 - Flags: review?(dolske)
Dolske, I think this patch is pretty easy and would be a high value for the Mobile Startup Shrink effort. When do you think you can review it?
the storage usage in this component seems confusing, I hope bug 566746 will do a better work on it, I don't really see reasons why this is synchronous, are there valid use-cases requiring that? Why do you need both dbConnection and DBConnection? couldn't you just have DBConnection and use getOwnPropertyDescriptor to check if it's a getter yet?
why do you invoke lazyDBInit() in dbMigrateToVersion3 if you immediately use DBConnection and the code uses DBConnection even before invoking dbMigrateToVersion3. I'd expect that to throw on migration
(In reply to Mounir Lamouri (:volkmar) (:mounir) from comment #10) > Created attachment 564529 [details] [diff] [review] [diff] [details] [review] > Patch v2.1 Mounir - I think you attached the wrong patch
Attached patch Patch v2.1 (obsolete) — Splinter Review
Attachment #564529 - Attachment is obsolete: true
Attachment #564529 - Flags: review?(dolske)
Attachment #564767 - Flags: review?(dolske)
Sorry, I'm annoying :) I still don't understand why you need _dbConnection, dbInit as well as lazyDBInit may just use a local var and return the created connection so that DBConnection just returns this.DBConnection = this.lazyDbInit(); dbInit may even be defined as an helper function inside lazyDBInit.
Comment on attachment 564767 [details] [diff] [review] Patch v2.1 >+ // The dabatase connection. You should use this.DBConnection instead, >+ // except in |get DBConnection| and in |lazyDbInit()| and |dbInit()|. >+ _dbConnection : null, No one will ever read this comment. :) It would be a lot simpler do just make |dbCommection| a self-memoizing getter and not rename it everywhere. That just needlessly inflates the diff. But, really, zpao and I talked about then when rewriting it. There wasn't any point in doing this, because everything in nsIFormHistory requires the DB. In other words, why is some caller triggering the creation of the component, and is it just going to immediately call an API anyway?
Attachment #564767 - Flags: review?(dolske) → review-
(In reply to Justin Dolske [:Dolske] from comment #17) > But, really, zpao and I talked about then when rewriting it. There wasn't > any point in doing this, because everything in nsIFormHistory requires the > DB. In other words, why is some caller triggering the creation of the > component, and is it just going to immediately call an API anyway? In Firefox Mobile (multi-process), we init the component so the child process scripts can get loaded - not because we want to use the component. But nsFormHistory.init() does both. If we don't load the child process scripts, the content will never get the form submit code activated.
Blocks: 673253
Attached patch Patch v3 (obsolete) — Splinter Review
I will have to double-check that the initialization is actually done once. I'm quite not sure about this...
Attachment #564767 - Attachment is obsolete: true
Object.getOwnPropertyDescriptor(this, "dbConnection").value === undefined can tell you if dbConnection is still a getter in dbInit(), if it's not then something is invoking it wrongly.
Blocks: 693536
Attached patch Patch v3.1Splinter Review
This new patch should take into account all comments.
Attachment #565834 - Attachment is obsolete: true
Attachment #566229 - Flags: review?(dolske)
BTW, might be interesting to remove DBConnection getter, it's pretty useless. Though, it's a pain to check where it's currently used. Looking for ".DBConnection" returns 172 results in mxr... I'm too lazy to check which ones are related to FormHistory.
(In reply to Mounir Lamouri (:volkmar) (:mounir) from comment #22) > BTW, might be interesting to remove DBConnection getter, it's pretty > useless. Though, it's a pain to check where it's currently used. Looking for > ".DBConnection" returns 172 results in mxr... I'm too lazy to check which > ones are related to FormHistory. I'm pretty sure Sync uses it directly, at least until we have async APIs.
(In reply to Paul O'Shannessy [:zpao] from comment #23) > (In reply to Mounir Lamouri (:volkmar) (:mounir) from comment #22) > > BTW, might be interesting to remove DBConnection getter, it's pretty > > useless. Though, it's a pain to check where it's currently used. Looking for > > ".DBConnection" returns 172 results in mxr... I'm too lazy to check which > > ones are related to FormHistory. > > I'm pretty sure Sync uses it directly, at least until we have async APIs. Anything against using one form vs another? (|FormHistory.dbConnection| vs |formHistory.DBConnection|)? I vote for |FormHistory.DBConnection| to not break everything in the outside world, and I agree with Mounir's that having two names that closed is confusing.
(In reply to Vivien Nicolas (:vingtetun) from comment #24) > (In reply to Paul O'Shannessy [:zpao] from comment #23) > > (In reply to Mounir Lamouri (:volkmar) (:mounir) from comment #22) > > > BTW, might be interesting to remove DBConnection getter, it's pretty > > > useless. Though, it's a pain to check where it's currently used. Looking for > > > ".DBConnection" returns 172 results in mxr... I'm too lazy to check which > > > ones are related to FormHistory. > > > > I'm pretty sure Sync uses it directly, at least until we have async APIs. > > Anything against using one form vs another? (|FormHistory.dbConnection| vs > |formHistory.DBConnection|)? > > I vote for |FormHistory.DBConnection| to not break everything in the outside > world, and I agree with Mounir's that having two names that closed is > confusing. .dbConnection is indeed only used internally. Once this patch is landed I will open a follow-up to rename dbConnection to DBConnection internally and remove dbConnection.
Comment on attachment 566229 [details] [diff] [review] Patch v3.1 I'd actually like to eventually move to some better way of having things hook up their listeners on startup... But I'm not sure what that would look like, exactly, so this is quite fine until then!
Attachment #566229 - Flags: review?(dolske) → review+
Whiteboard: [mobilestartupshrink][needs review] → [mobilestartupshrink][needs try]
Whiteboard: [mobilestartupshrink][needs try] → [mobilestartupshrink][inbound]
Status: ASSIGNED → RESOLVED
Closed: 14 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla10
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: