Closed
Bug 48486
Opened 24 years ago
Closed 24 years ago
LiteralImpl has a nsAutoString member, should it?
Categories
(Core Graveyard :: RDF, defect, P3)
Tracking
(Not tracked)
VERIFIED
FIXED
M18
People
(Reporter: jband_mozilla, Assigned: waterson)
Details
(Keywords: memory-footprint, Whiteboard: FIX IN HAND)
Attachments
(4 files)
1.39 KB,
patch
|
Details | Diff | Splinter Review | |
3.23 KB,
patch
|
Details | Diff | Splinter Review | |
3.62 KB,
patch
|
Details | Diff | Splinter Review | |
2.59 KB,
patch
|
Details | Diff | Splinter Review |
about:bloat shows:
76 LiteralImpl 164 52152 382 318 ( 166.28 +/- 101.20)
4319 482 ( 306.04 +/- 140.82)
I see we leak LiteralImpls too.
Does the speed or the likely length of the contents justify the use of
nsAutoString?
Assignee | ||
Comment 1•24 years ago
|
||
jband: no, even use of nsString is not justified here. Could you file leaks on
me as a separate bug.
Assignee | ||
Comment 2•24 years ago
|
||
Reporter | ||
Comment 3•24 years ago
|
||
r=jband
P.S. I can't reproduce the leak I saw. It was after some odd assert after a JS
code screwup that I 'ignored'. Looks like a fslse alarm on the leak.
Assignee | ||
Comment 4•24 years ago
|
||
Assignee | ||
Comment 5•24 years ago
|
||
cc'ing scc, who may know better C++ kung fu...what do you think of the last
patch? Is there a "preferred" way of doing what I'm trying to do?
Status: NEW → ASSIGNED
Target Milestone: --- → M18
Comment 6•24 years ago
|
||
for the implementation of |PRUnichar* nsCRT::strcpy(PRUnichar* aDest, const
PRUnichar* aSource)|, you'll want to use |wmemcpy| if it is available.
You can't glue together the object with data using a member variable at the end
being the start of the array. It's just too dangerous. The C++ compiler does
not give you enough guarantees about object layout to make this work. The right
way to do this is shown in
<http://lxr.mozilla.org/seamonkey/source/xpcom/ds/nsSharedString.h#174>
don't use the array allocator, use raw |operator new|, then placement |new| (line
186) to get construction to happen. The math at the beginning of this function
ensures proper alignment of the variable sized data buffer.
In fact, is there any reason that |nsShared[C]String| couldn't be your answer
here? It doesn't carry much overhead per instance: just a vptr, a reference
count, the length of the string, and (unfortunately) a pointer to the databuffer
that falls just off the end of the structure, see
<http://lxr.mozilla.org/seamonkey/source/xpcom/ds/nsSharedString.h#88>
No biggie if even this is too much, but use this construction scheme as your
guide.
Assignee | ||
Comment 7•24 years ago
|
||
Assignee | ||
Comment 8•24 years ago
|
||
scc: incorporated your feedback, modulo:
1. wmemcpy() would require us to strlen(); is that really going to be better? I
suppose I could improve on the code in LiteralImpl::Create() to do a memcpy()...
2. Can't use nsSharedString b/c need to support nsIRDFLiteral. In all other ways
this is an nsIAtom/nsSharedString. Oh well, we'll fix it in RDF 2.0.
Let me know if any other comments...
Assignee | ||
Comment 9•24 years ago
|
||
FWIW, I'd estimate memory savings are ~140 bytes per LiteralImpl (raw object
size down to 12 bytes from 164; assume the string is five to ten characters --
ten to twenty bytes). I created about 600 LiteralImpl objects doing a "typical"
run, including mail/news. So this is on the order of a 50KB to 100KB win.
Assignee | ||
Comment 10•24 years ago
|
||
Assignee | ||
Comment 11•24 years ago
|
||
fixed
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Updated•6 years ago
|
Product: Core → Core Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•