Closed Bug 927078 Opened 12 years ago Closed 12 years ago

Don't copy string data when sending messages using message manager

Categories

(Core :: IPC, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla30
blocking-b2g 1.3T+
Tracking Status
b2g-v1.3T --- fixed

People

(Reporter: smaug, Assigned: smaug)

References

Details

Attachments

(2 files, 1 obsolete file)

We could just improve nsDependentString a bit and use it to pass data to IPC layer. Patch coming.
Attached patch patch (obsolete) — Splinter Review
nsDependentString is a bit error prone, but the patch doesn't make it any worse. Requirement to pass null-terminated string to it is left to the caller anyway. (And need to fix the name AssertValidDepedentString at some point, but not in this bug)
Attachment #817431 - Flags: review?(benjamin)
Comment on attachment 817431 [details] [diff] [review] patch The constructor seems like a footgun for future generations. Could we make the callsites intentionally uglier so that instead of nsDependentString(aMessage) its nsDependentString(aMessage.BeginReading(), aMessage.Length()) ? But also more generally, how do you know that aMessage (in ChildProcessMessageManagerCallback::DoSendBlockingMessage) actually is null-terminated? I don't see any external guarantees of that.
(In reply to Benjamin Smedberg [:bsmedberg] from comment #2) > The constructor seems like a footgun for future generations. Not more than our current nsDependentString ctors > > But also more generally, how do you know that aMessage (in > ChildProcessMessageManagerCallback::DoSendBlockingMessage) actually is > null-terminated? I don't see any external guarantees of that. Well, we get null-terminated strings from JS. and MM is JS-only API. I could do something uglier but safer - basically check whether the string is null terminated and only then use DependentString and otherwise copy data.
Attachment #817431 - Flags: review?(benjamin)
Hi Olli, we're looking for any little wins we can get for tarako. Any time to finish this up?
Flags: needinfo?(bugs)
/me doesn't know what tarako is.
But sure, I could take a look at this again.
Flags: needinfo?(bugs)
(In reply to Olli Pettay [:smaug] from comment #5) > /me doesn't know what tarako is. It's a FxOS device with 128MiB of RAM, so it's a platform where every bit counts (literally). See the wiki page for more info https://wiki.mozilla.org/FirefoxOS/Tarako
Something like this then. Safer, and removes still lots of extra copying. https://tbpl.mozilla.org/?tree=Try&rev=8bfa74513f7f
Attachment #817431 - Attachment is obsolete: true
Attachment #8375896 - Flags: review?(benjamin)
Whiteboard: [tarako]
Comment on attachment 8375896 [details] [diff] [review] maybedependentstring.diff r=me but I'd like dbaron to review the API as well.
Attachment #8375896 - Flags: superreview?(dbaron)
Attachment #8375896 - Flags: review?(benjamin)
Attachment #8375896 - Flags: review+
Attachment #8375896 - Flags: superreview?(dbaron)
Attachment #8375896 - Flags: superreview?(dbaron)
How is this different from the existing PromiseFlat[C]String functions, which use the nsPromiseFlat[C]String class?
Flags: needinfo?(bugs)
(We should probably rename those from PromiseFlat to PromiseTerminated, given that we no longer have multi-fragment strings. Flat is the name we used meaning both single-fragment and terminated.)
Comment on attachment 8375896 [details] [diff] [review] maybedependentstring.diff I don't see any difference between this and PromiseFlatString; I think you should just use that.
Attachment #8375896 - Flags: superreview?(dbaron) → superreview-
Crap, we have two kinds of PromiseFlatStrings. One which is useful, and one in glue which is just typedef from nsString. And I was aware of only the latter. I didn't know PromiseFlatStrings had this kind of odd side effect.
(We should not have inconsistent APIs. glue exposing totally different API behavior with the same name is horrible.)
Flags: needinfo?(bugs)
The glue version does in fact promise a flat string. It just always performs a share or a copy instead of sometimes doing a dependent string, because the glue API isn't aware of the flags for that. And it was necessary to add this to the glue to compile mailnews in some configurations.
Attachment #8379705 - Flags: review?(benjamin)
Attachment #8379705 - Flags: review?(benjamin) → review+
Status: NEW → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla30
blocking-b2g: --- → 1.3T?
Whiteboard: [tarako]
Hi Olli, I wonder if we know how much memory saving this patch can provide? trying to evaluate if this is needed for Tarako project (128MB RAM Firefox OS project). thanks
Flags: needinfo?(bugs)
This is more performance win than memory saving. Well, it reduces memory usage too, but that just a short amount memory during a very short period.
Flags: needinfo?(bugs)
blocking-b2g: 1.3T? → 1.3T+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: