diff options
author | Patrick Walton <pcwalton@mimiga.net> | 2015-03-18 21:06:02 -0700 |
---|---|---|
committer | Patrick Walton <pcwalton@mimiga.net> | 2015-04-01 08:58:16 -0700 |
commit | 750bbed2cbdd37677b9298c86e20fb6a2db33b23 (patch) | |
tree | 0ae3e3ac81eabd2a957a45293b8041ac5a470472 /components/gfx/font_cache_task.rs | |
parent | 6824bc93241d8ad6eff30e5014d27b88ea8a65d7 (diff) | |
download | servo-750bbed2cbdd37677b9298c86e20fb6a2db33b23.tar.gz servo-750bbed2cbdd37677b9298c86e20fb6a2db33b23.zip |
gfx: Perform more aggressive caching in
`FontContext::get_layout_font_group_for_style()`.
There are several optimizations here:
* We make font families atoms, to allow for quicker comparisons.
* We precalculate an FNV hash of the relevant fields of the font style
structure.
* When obtaining a platform font group, we first check pointer equality
for the font style. If there's no match, we go to the FNV hash. Only
if both caches miss do we construct and cache a font group. Note that
individual fonts are *also* cached; thus there are two layers of
caching here.
15% improvement in total layout thread time for Facebook Timeline.
Diffstat (limited to 'components/gfx/font_cache_task.rs')
-rw-r--r-- | components/gfx/font_cache_task.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/components/gfx/font_cache_task.rs b/components/gfx/font_cache_task.rs index 8a87ed9fdb0..e22fe434f85 100644 --- a/components/gfx/font_cache_task.rs +++ b/components/gfx/font_cache_task.rs @@ -9,16 +9,17 @@ use platform::font_list::get_last_resort_font_families; use platform::font_context::FontContextHandle; use collections::str::Str; +use font_template::{FontTemplate, FontTemplateDescriptor}; +use net::resource_task::{ResourceTask, load_whole_resource}; +use platform::font_template::FontTemplateData; use std::borrow::ToOwned; use std::collections::HashMap; use std::sync::Arc; use std::sync::mpsc::{Sender, Receiver, channel}; -use font_template::{FontTemplate, FontTemplateDescriptor}; -use platform::font_template::FontTemplateData; -use net::resource_task::{ResourceTask, load_whole_resource}; -use util::task::spawn_named; -use util::str::LowercaseString; +use string_cache::Atom; use style::font_face::Source; +use util::str::LowercaseString; +use util::task::spawn_named; /// A list of font templates that make up a given font family. struct FontFamily { @@ -77,7 +78,7 @@ impl FontFamily { pub enum Command { GetFontTemplate(String, FontTemplateDescriptor, Sender<Reply>), GetLastResortFontTemplate(FontTemplateDescriptor, Sender<Reply>), - AddWebFont(String, Source, Sender<()>), + AddWebFont(Atom, Source, Sender<()>), Exit(Sender<()>), } @@ -315,7 +316,7 @@ impl FontCacheTask { } } - pub fn add_web_font(&self, family: String, src: Source) { + pub fn add_web_font(&self, family: Atom, src: Source) { let (response_chan, response_port) = channel(); self.chan.send(Command::AddWebFont(family, src, response_chan)).unwrap(); response_port.recv().unwrap(); |