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.
This commit is contained in:
Patrick Walton 2015-03-18 21:06:02 -07:00
parent 6824bc9324
commit 750bbed2cb
14 changed files with 144 additions and 62 deletions

View file

@ -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();