Closed Bug 311458 Opened 19 years ago Closed 19 years ago

Appending a single char to a string does a memcpy

Categories

(Core :: XPCOM, defect)

x86
Linux
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 312681

People

(Reporter: bzbarsky, Unassigned)

References

(Blocks 1 open bug)

Details

(Keywords: perf)

It looks like we treat a single char as a length-one char buffer... would it
possibly be faster to just assign to the right location instead of doing a
memcpy (via char_traits::copy)?
Sure... do we have any data to prove that this may be worth the effort?
Where is this code? It sounds like it might be better for the CSS code to
construct a local dependentconcatenation and then append it at once.  Of course
the dependentconcatenation code doesn't deal with single chars (perhaps a
special single-char class could be arranged, I'm not very familiar with the
internals there).
I was looking at a profile that does a bunch of canvas operations... setting the
fill color looks like this (all numbers are hits under the method):

24020 nsCanvasRenderingContext2D::SetFillStyle(nsIVariant*)

of which

14334 CSSParserImpl::ParseColorString

of which

1365 nsSubstring::Replace

That's about 10% of the total CSS parse time here.  For general CSS it's a bit
better, but not much -- still about 5%, as I recall.

I'm not sure how much of this is bug 311456 though, so maybe we should fix that
first...
Depends on: 311456
The code in question is nsCSSScanner::GatherIdent.  Between pushback and
character escapes, this might be nontrivial to do in a way that doesn't involve
appending a char at a time.
So, you believe that a large portion of the cost is the memcpy call done by
Replace?  Enough to warrant an additional codepath in the string module?
OK, I dug about a bit, and it looks like nsSubstring::Replace breaks down as
(1365 hits total):

529 hits in the function itself
612 hits under nsSubstring::ReplacePrep(unsigned, unsigned, unsigned)
190 hits under memcpy

So yeah, memcpy doesn't seem to be a big deal here.  I'll reprofile once we
decide what we're doing with bug 311456, if anything.
Probably not really an issue, based on more profile-reading.
Status: NEW → RESOLVED
Closed: 19 years ago
Resolution: --- → INVALID
Looks like this got fixed after all.
Status: RESOLVED → REOPENED
Resolution: INVALID → ---

*** This bug has been marked as a duplicate of 312681 ***
Status: REOPENED → RESOLVED
Closed: 19 years ago19 years ago
Resolution: --- → DUPLICATE
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.