Closed Bug 310708 Opened 19 years ago Closed 19 years ago

[BeOS]Font width cache to be implemented

Categories

(Core Graveyard :: GFX: BeOS, defect)

Other
BeOS
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: sergei_d, Assigned: sergei_d)

References

Details

(Keywords: verified1.8.1)

Attachments

(1 file, 5 obsolete files)

It is about last HUGE performance bottleneck in our GFX layer (there are others, but much less important) For sites which use specual char alignment (like align=justify) )Mozilla permanently calculates placement for each char, and to calculate this placement, it should permanently ask char widths. But in BeOS each call for String/CharWidth, be it BView method or BFont method, actually calls app_server, which brings HUGE overhead and slowdown. Like 5000 extra appserver calls for page. Workaround is to create special cache, where you storage widths for already "tested" chars for given font. Actually it is not trivial task,sometimes very non-trivial, but even simplest implementation I tested here gives us fantastic speed improvement. Current price is that for each mFontMetrics object ( it uses additional memory - float foo[OxFFFF]. Unfortunately. With time and work it may be reduced and optimized, but for me it is already worth submitting and testing. Because even with simpicistic implementation performance boost is fantastic.
Attached patch patch - draft implementation (obsolete) — Splinter Review
Preliminary but worth testing.
Comment on attachment 198155 [details] [diff] [review] patch - draft implementation something went wrong in if()s
Attachment #198155 - Attachment is obsolete: true
Attached patch patch (obsolete) — Splinter Review
This one seems working again
Notice for curious. Previous patch is rather proof of concept. Being fastest but memory hog. Kind of. Actual implementation will use hash-table. In future there is sence to make it global, but it needs rewrite of nsFontMetricsBeOS in order to make cacheable (and hasheable) font descriptions, and to resolve possible thread-safety problem. Thus, at the moment it looks like good idea to restrict ourselves only by font-width cache unique for nsFontMetrics instance.
Attached patch patch with hashtable (obsolete) — Splinter Review
Reimplemented using nsHashtable. For key generating from single UTF-8 character I use nsCStringKey(). Biesi, timeless, can you look at? I never used nsHashtable, do don't know, for example, if simple Reset() is enough to free all new-ed width entries (as hashtable gets those as (void *)).
Attachment #198208 - Attachment is obsolete: true
Attached patch patch (obsolete) — Splinter Review
taking in account some timeless notices, logic is same asin previous
Assignee: beos → sergei_d
Status: NEW → ASSIGNED
This patch isn't working, it has different variablename for hashtable in header and source.
Attached patch patch - for whole strings (obsolete) — Splinter Review
Here is patch which tries to calculate whole string width from cached char widths. But it works sometimes bit strange - some strings get too wide-spaced. Performance of this version is higher than previous, but issue needs investigation. At moment I prefer to have previous patch as production-ready.
The last two patches are broken. You use mFontWidthCache in code and mWidthFontCache in header. I wonder if you tested the right builds.
Using nsDataHashtable. Single-char version. Also added explicit setting for B_FIXED_SPACING for font - char and string spacing don't work for us here anyway. Removed direct links to system fonts in fallback case - that was bit dangerous and didn't allow to control some font parameters. Changed line in EnumFonts according biesi comment: https://bugzilla.mozilla.org/show_bug.cgi?id=310680#c10
Attachment #198156 - Attachment is obsolete: true
Attachment #198209 - Attachment is obsolete: true
Attachment #198211 - Attachment is obsolete: true
Comment on attachment 198222 [details] [diff] [review] patch with nsDataHashtable review request
Attachment #198222 - Flags: review?(thesuckiestemail)
Comment on attachment 198222 [details] [diff] [review] patch with nsDataHashtable r=thesuckiestemail@yahoo.se I'm not very good at the utf-'magic' but it looks good to me and seems to work ok.
Attachment #198222 - Flags: review?(thesuckiestemail) → review+
Patch landed in trunk: nsFontMetricsBeOS.cpp new revision: 1.43; previous revision: 1.42 nsFontMetricsBeOS.h new revision: 1.13; previous revision: 1.12 nsRenderingContextBeOS.cpp new revision: 1.55; previous revision: 1.54
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
might the APIs from bug 297074 help here too?
There must be little follow-up to this bug. Curently "biggest" versopn nsRenderingContextBeOS::::GetTextDimensions() uses mFont->StringWidth() - it means non-cached BView::StringWidth(); For most time, in theory, GetTextDimensions asks for longer than one character strings, so it shouldn't matter with current GetStringWidth() implementation, but in future it might do. So I will move it to unified way. Second problem is BeOS and Mozilla different understanding about widths. In other cases it differs by one, but i'm yet sure if it matters for StringWidth(). Looks like it does, so why i failed to calculate, even with fixed spacing, string width from cached char widths.
Thanks biesi. As i already planned changes in nsRenderingContext, i will look at bug you pointed. Though, patch looks huge there:)
Blocks: 311032
Comment on attachment 198222 [details] [diff] [review] patch with nsDataHashtable Requesting approval for landing in the MOZILLA_1_8_BRANCH. This is a BeOS-only change and does not affect other platforms.
Attachment #198222 - Flags: approval1.8.1?
Comment on attachment 198222 [details] [diff] [review] patch with nsDataHashtable a=schrep for drivers.
Attachment #198222 - Flags: approval1.8.1? → approval1.8.1+
Checking in mozilla/gfx/src/beos/nsFontMetricsBeOS.cpp; /cvsroot/mozilla/gfx/src/beos/nsFontMetricsBeOS.cpp,v <-- nsFontMetricsBeOS.cpp new revision: 1.40.12.3; previous revision: 1.40.12.2 done Checking in mozilla/gfx/src/beos/nsFontMetricsBeOS.h; /cvsroot/mozilla/gfx/src/beos/nsFontMetricsBeOS.h,v <-- nsFontMetricsBeOS.h new revision: 1.12.12.1; previous revision: 1.12 done Checking in mozilla/gfx/src/beos/nsRenderingContextBeOS.cpp; /cvsroot/mozilla/gfx/src/beos/nsRenderingContextBeOS.cpp,v <-- nsRenderingContextBeOS.cpp new revision: 1.51.12.4; previous revision: 1.51.12.3 done
Keywords: verified1.8.1
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: