Closed Bug 80106 Opened 25 years ago Closed 23 years ago

[charset]Improve @charset parsing in CSSLoaderImpl::SetCharset

Categories

(Core :: CSS Parsing and Computation, defect, P5)

defect

Tracking

()

RESOLVED FIXED
Future

People

(Reporter: nhottanscp, Assigned: bzbarsky)

References

Details

(Keywords: helpwanted, perf)

Attachments

(1 file, 3 obsolete files)

Separated from bug 72658. http://lxr.mozilla.org/seamonkey/source/content/html/style/src/nsCSSLoader.cpp#1607 Quoted from bug 72658. > ------- Additional Comments From David Baron 2001-05-09 13:14 ------- > > I think it would be nice if we didn't make a copy of all of the data in (the > beginning of?) the stylesheet (at least I'm guessing that's what > |aStyleSheetData| is) after the @charset and then call > |nsString::StripWhitespace| on it, just to get an nsAutoString that contains > what's between the @charset and the ; following. This could be done easily by > switching the order of the |aStyleSheetData.Find| (which is now |str.Find|) and > the |aStyleSheetData.Mid| and using the third parameter to |nsString::Find| or > (a bit less easily considering the current code) using an nsPromiseSubstring (to > avoid any copying at all). > > (I'm also a bit concerned that we're not parsing the @charset according to CSS's > parsing rules.)
It would also be good not to do an extra one-byte -> two-byte conversion in SheetLoadData::OnStreamComplete. That conversion might make somee sense if AssignWithConversion did a UTF8->UCS2 conversion, but it doesn't. (It does ISO-8859-1 to UCS2 conversion.)
Summary: Improve @charset parsing in CSSLoaderImpl::SetCharset → [charset]Improve @charset parsing in CSSLoaderImpl::SetCharset
Target Milestone: --- → mozilla1.0
Attached patch Proposed patch (obsolete) — Splinter Review
Taking this.... The attached patch does the following: 1) Uses dependent strings to avoid having to make a string copy for the @charset parsing 2) Changes the parsing somewhat to be more compliant with the CSS2 grammar (the two LookForCharsetRule functions). 3) Eliminates the string copy that we used to do to get a unichar stream. We now just create a unicode conversion stream and convert as we go. (should save some memory allocation if nothing else). 4) Take all the charset handling out of the CSSLoader proper and move it into static functions called directly by the LoadData, since that's what handles the decoding anyway. I profiled this and I _think_ I see a bit of a speed increase, but my data is not too trustworthy... my jprof profiles of startup had 200-250 hits total, with 0-3 of them in the @charset parsing stuff. With my changes that dropped to 0-1 instead of 0-3, but I'd love it if someone with a slower machine or a better profiling setup would profile this one... Also, any suggestions on 4-byte encodings and what to do with them are very much welcome. :)
Assignee: pierre → bzbarsky
Keywords: patch, review
Target Milestone: mozilla1.0 → mozilla0.9.6
Comment on attachment 55132 [details] [diff] [review] Proposed patch um... that would be the wrong patch file. :)
Attachment #55132 - Attachment is obsolete: true
Attached patch Patch that actually compiles (obsolete) — Splinter Review
Depends on: 106843
Comment on attachment 55140 [details] [diff] [review] Patch that actually compiles Attaching less ambitious page
Attachment #55140 - Attachment is obsolete: true
Attached patch Patch that fixes _this_ bug. (obsolete) — Splinter Review
I've focused the patch more on the actual @charset rule parsing. The other things it did will be resolved in bug 106843, which this no longer depends on. Reviews?
No longer depends on: 106843
Oh. I'll remove the #ifdef DEBUG_bzbarsky stuff before checking this in, by the way. Just so people know as they review.
Comment on attachment 55408 [details] [diff] [review] Patch that fixes _this_ bug. comparators have changed headers
Attachment #55408 - Attachment is obsolete: true
Attached patch Patch v.3Splinter Review
I won't be able to spend much time on reviewing this cleanup but at first sight: - The CSSLoader should not deal with encoding issues the way it is done in GetCharsetFromData(). - The two LookForCharsetRule functions are quite redundant. - We neeed more data about the benefits of this patch in terms of performance and memory footprint.
> The CSSLoader should not deal with encoding issues the way it is done in > GetCharsetFromData(). Well... We have to know whether it's a single-byte or multi-byte encoding to usefully look for _anything_ in the raw data. Our current behavior breaks for multi-byte encodings as far as I can tell. We could just stay compatible with that, but that seems wrong. nhotta, is there an intl API for doing what we want done there? I'll work on the other two points.
Status: NEW → ASSIGNED
Keywords: patch, review
Priority: -- → P3
QA Contact: ian
Summary: [charset]Improve @charset parsing in CSSLoaderImpl::SetCharset
Target Milestone: mozilla0.9.6 → mozilla0.9.7
QA Contact: ian
Summary: [charset]Improve @charset parsing in CSSLoaderImpl::SetCharset
OK. I've done some measurements and had rjesup profile this as well. As far as I can tell, the time spent in this function is basically nearly zero. I cannot get a measurable time spent in it in current builds, so any changes that I make can't really be an improvement. Pushing this out till we have some data to show that this is actually a problem.
Priority: P3 → P5
Target Milestone: mozilla0.9.7 → mozilla0.9.9
so I posted about part of this bug on n.p.m.performance - the bit about passing around the stream loader instead of multiply copying the data being read in from necko. Here's an excerpt: --- In a startup of about:blank, we allocate and release 195k of these decoded style sheets in 29 allocations. It's the #4 weighted allocation of allocations lasting less than 4 seconds. Now, maybe it's just me, but we couldn't we use the i18n nsConverterInputStream, which has a fixed-size buffer where it does the conversion... we would take the raw char* string that comes from SheetLoadData::OnStreamComplete, and get a nsIUnicharInputStream, and pass THAT to the parser.. that would avoid the overhead of allocating memory for the entire decoded style sheet. -- so for bloat numbers, I would see a drop of probably about 200k on startup. I don't know about the charset parsing stuff though - should we split the above into a seperate bug?
Not getting to this anytime soon...
Keywords: helpwanted, perf
Target Milestone: mozilla0.9.9 → Future
Keywords: patch
Depends on: 119321
This got done as a side-effect of bug 119321.
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: