Closed
Bug 340603
Opened 19 years ago
Closed 19 years ago
getting table updates consumes large amounts of memory
Categories
(Toolkit :: Safe Browsing, defect)
Tracking
()
RESOLVED
FIXED
People
(Reporter: tony, Assigned: tony)
Details
(Keywords: fixed1.8.1)
Attachments
(3 files, 4 obsolete files)
|
35.75 KB,
patch
|
darin.moz
:
approval-branch-1.8.1+
|
Details | Diff | Splinter Review |
|
35.68 KB,
patch
|
Details | Diff | Splinter Review | |
|
9.15 KB,
patch
|
darin.moz
:
review+
darin.moz
:
approval-branch-1.8.1+
|
Details | Diff | Splinter Review |
Getting local table updates can consume large amounts of memory because we update as a single batch once the update file downloads (for a file of 8 mb, it uses about 16mb of memory). Instead, we should do a streaming update that incrementally updates the sqlite db.
| Assignee | ||
Comment 1•19 years ago
|
||
This just adds the interface. I'll update the JS code to use this in a separate patch.
Attachment #224646 -
Flags: review?(darin)
Attachment #224646 -
Flags: approval-branch-1.8.1?(darin)
Comment 2•19 years ago
|
||
Comment on attachment 224646 [details] [diff] [review]
v1: interface for streaming updates
bump the UUID for nsIUrlClassifierDBService
> nsUrlClassifierDBServiceWorker::Update(const nsACString& chunk) {
keep opening bracket style consistent.
+mPendingStreamUpdate("")
no need to initialize this in your ctor.
+ mTableUpdateLines.AppendElement(nsCString(line));
it may be more efficient to just pass |line| to AppendElement since the compiler should be smart enough to use the right nsCString constructor automatically. if it does that then you avoid a call to the copy constructor. another choice is to use the version of AppendElement that takes no arguments, and then call Assign on the new element.
+ mPendingStreamUpdate = "";
.Truncate() would be better.
r+a=darin w/ those changes
Attachment #224646 -
Flags: review?(darin)
Attachment #224646 -
Flags: review+
Attachment #224646 -
Flags: approval-branch-1.8.1?(darin)
Attachment #224646 -
Flags: approval-branch-1.8.1+
| Assignee | ||
Comment 3•19 years ago
|
||
Adding all the suggestions from Darin.
Attachment #224646 -
Attachment is obsolete: true
| Assignee | ||
Comment 4•19 years ago
|
||
Let's try this again. 3 files were missing from the last diff ns[I]?UrlClassifierStreamUpdater.{idl,cpp,h}.
Attachment #224795 -
Attachment is obsolete: true
Attachment #224804 -
Flags: review?(darin)
Attachment #224804 -
Flags: approval-branch-1.8.1?(darin)
Comment 5•19 years ago
|
||
Comment on attachment 224804 [details] [diff] [review]
v3: interface for streaming updates
>+++ toolkit/components/url-classifier/src/nsUrlClassifierStreamUpdater.cpp 9a48392cf8bfd057f16740bd00d5f9ccf678963d
>+TableUpdateListener::~TableUpdateListener()
>+{
>+}
nit: Maybe just implement this inline in the class decl so it can
be compiled away.
>+ // Copy the data into a nsCString
>+ char *buf = new char[aLength + 1];
>+ PRUint32 readLength;
>+
>+ rv = aIStream->Read(buf, aLength, &readLength);
>+ if (NS_FAILED(rv)) {
>+ NS_ASSERTION((NS_BASE_STREAM_WOULD_BLOCK != rv),
>+ "The stream should never block.");
>+ delete buf;
>+ return rv;
>+ }
>+
>+ buf[aLength] = '\0';
>+ nsCString chunk(buf);
>+ delete buf;
>+
>+ LOG(("Chunk: %s\n\n", chunk.get()));
>+
>+ rv = mDBService->Update(chunk);
OK, a couple comments:
1) you should use "delete[] buf" instead of "delete buf" since
the array was allocated using new[].
2) you can simplify this code quite a bit by doing the following:
nsCString chunk;
rv = NS_ConsumeStream(aIStream, aLength, chunk);
Just #include "nsStreamUtils.h" to get this helper function.
>+ nsUrlClassifierStreamUpdater* updater =
>+ NS_REINTERPRET_CAST(nsUrlClassifierStreamUpdater*, context);
NS_STATIC_CAST should work since nsUrlClassifierStreamUpdater inherits
from nsISupports.
>+nsUrlClassifierStreamUpdater::~nsUrlClassifierStreamUpdater()
>+{
>+}
ditto
>+NS_IMETHODIMP
>+nsUrlClassifierStreamUpdater::SetUpdateUrl(const nsACString & aUpdateUrl)
>+{
>+ nsresult rv = NS_NewURI(getter_AddRefs(mUpdateUrl), aUpdateUrl);
>+ if (NS_FAILED(rv)) {
>+ mUpdateUrl = nsnull;
>+ return rv;
It may be a good idea to have this setter keep the state of the object
unchanged when it fails. That means only assigning to mUpdateUrl if
NS_NewURI created a nsIURI successfully.
Also, bear in mind that NS_NewURI also takes a charset parameter that
tells it how to encode non-ASCII characters (i.e., whether they should
be converted from UTF-8 to Shift-JIS for example before they are %-escaped).
I don't know if it matters for SetUpdateUrl, but you might want to
consider the consequences of not having a way to convey that charset info
to NS_NewURI.
>+ rv = NS_NewChannel(getter_AddRefs(channel), mUpdateUrl);
>+
>+ if (!mListener) {
>+ mListener = new TableUpdateListener(c);
>+ }
>+
>+ // Make the request
>+ channel->AsyncOpen(mListener.get(), this);
>+ mIsUpdating = PR_TRUE;
>+
>+ return NS_OK;
>+}
This will crash is NS_NewChannel failed for some reason.
r=darin w/ these issues fixed
Attachment #224804 -
Flags: review?(darin) → review+
Comment 6•19 years ago
|
||
Comment on attachment 224804 [details] [diff] [review]
v3: interface for streaming updates
post a revised patch and i'll approve it for FF2
Attachment #224804 -
Flags: approval-branch-1.8.1?(darin)
| Assignee | ||
Comment 7•19 years ago
|
||
Incorporated all the changes. Added a comment to the idl file about character encoding for the url. I guess it's ok to require data providers to use ascii update urls.
Also added a CancelStream method to the DB interface so we can rollback the transaction if the download fails (i.e., status in onStopRequest fails).
Attachment #224804 -
Attachment is obsolete: true
Attachment #225233 -
Flags: approval-branch-1.8.1?(darin)
Comment 8•19 years ago
|
||
Comment on attachment 225233 [details] [diff] [review]
v4: interface for streaming updates
sorry for the delay on this approval!
Attachment #225233 -
Flags: approval-branch-1.8.1?(darin) → approval-branch-1.8.1+
| Assignee | ||
Comment 9•19 years ago
|
||
For completeness, adding the bonecho patch.
| Assignee | ||
Comment 10•19 years ago
|
||
Bleh, missed new files. Correct patch for bonecho.
Attachment #225506 -
Attachment is obsolete: true
| Assignee | ||
Comment 11•19 years ago
|
||
"interface for streaming updates" patch is on trunk and branch. Leaving bug open for second patch that uses this interface from the JS code.
| Assignee | ||
Comment 12•19 years ago
|
||
This patch actually turns on the use of the streaming interface.
Attachment #225778 -
Flags: review?(darin)
Attachment #225778 -
Flags: approval-branch-1.8.1?(darin)
Updated•19 years ago
|
Attachment #225778 -
Flags: review?(darin)
Attachment #225778 -
Flags: review+
Attachment #225778 -
Flags: approval-branch-1.8.1?(darin)
Attachment #225778 -
Flags: approval-branch-1.8.1+
| Assignee | ||
Comment 13•19 years ago
|
||
fixed on branch and trunk
Updated•11 years ago
|
Product: Firefox → Toolkit
You need to log in
before you can comment on or make changes to this bug.
Description
•