Closed
Bug 690903
Opened 14 years ago
Closed 14 years ago
nsFormHistory should lazily initializes SQLite DB
Categories
(Toolkit :: Form Manager, defect)
Toolkit
Form Manager
Tracking
()
RESOLVED
FIXED
mozilla10
People
(Reporter: mfinkle, Assigned: mounir)
References
Details
(Keywords: mobile, perf, Whiteboard: [mobilestartupshrink][inbound])
Attachments
(1 file, 5 obsolete files)
4.83 KB,
patch
|
Dolske
:
review+
|
Details | Diff | Splinter Review |
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.
Assignee | ||
Comment 1•14 years ago
|
||
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
Blocks: 634792
Reporter | ||
Comment 2•14 years ago
|
||
(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.
Assignee | ||
Comment 3•14 years ago
|
||
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.
Reporter | ||
Comment 4•14 years ago
|
||
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.
Assignee | ||
Comment 5•14 years ago
|
||
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 | ||
Updated•14 years ago
|
Flags: in-testsuite-
Whiteboard: mobilestartupshrink → [mobilestartupshrink][needs review]
Assignee | ||
Comment 6•14 years ago
|
||
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...
Reporter | ||
Comment 7•14 years ago
|
||
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()
Assignee | ||
Comment 8•14 years ago
|
||
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)
Reporter | ||
Comment 9•14 years ago
|
||
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+
Assignee | ||
Comment 10•14 years ago
|
||
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)
Assignee | ||
Comment 11•14 years ago
|
||
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?
Comment 12•14 years ago
|
||
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?
Comment 13•14 years ago
|
||
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
Reporter | ||
Comment 14•14 years ago
|
||
(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
Assignee | ||
Comment 15•14 years ago
|
||
Attachment #564529 -
Attachment is obsolete: true
Attachment #564529 -
Flags: review?(dolske)
Attachment #564767 -
Flags: review?(dolske)
Comment 16•14 years ago
|
||
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 17•14 years ago
|
||
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-
Reporter | ||
Comment 18•14 years ago
|
||
(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.
Assignee | ||
Comment 19•14 years ago
|
||
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
Comment 20•14 years ago
|
||
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.
Assignee | ||
Comment 21•14 years ago
|
||
This new patch should take into account all comments.
Attachment #565834 -
Attachment is obsolete: true
Attachment #566229 -
Flags: review?(dolske)
Assignee | ||
Comment 22•14 years ago
|
||
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.
Comment 23•14 years ago
|
||
(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.
Comment 24•14 years ago
|
||
(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.
Assignee | ||
Comment 25•14 years ago
|
||
(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 26•14 years ago
|
||
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+
Assignee | ||
Updated•14 years ago
|
Whiteboard: [mobilestartupshrink][needs review] → [mobilestartupshrink][needs try]
Assignee | ||
Updated•14 years ago
|
Whiteboard: [mobilestartupshrink][needs try] → [mobilestartupshrink][inbound]
Comment 27•14 years ago
|
||
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.
Description
•