Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch hash table and maps to use FxHash instead of Fnv. #1538

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webrender/Cargo.toml
Expand Up @@ -18,7 +18,7 @@ bincode = "0.8"
bit-set = "0.4"
byteorder = "1.0"
euclid = "0.15.1"
fnv = "1.0"
fxhash = "0.2.1"
gleam = "0.4.7"
lazy_static = "0.2"
log = "0.3"
Expand Down
8 changes: 4 additions & 4 deletions webrender/build.rs
Expand Up @@ -14,7 +14,7 @@ fn write_shaders(glsl_files: Vec<PathBuf>, shader_file_path: &Path) {
write!(shader_file, "use std::collections::HashMap;\n").unwrap();
write!(shader_file, "lazy_static! {{\n").unwrap();
write!(shader_file, " pub static ref SHADERS: HashMap<&'static str, &'static str> = {{\n").unwrap();
write!(shader_file, " let mut h = HashMap::with_capacity({});\n", glsl_files.len()).unwrap();
write!(shader_file, " let mut h = HashMap::new();\n").unwrap();
for glsl in glsl_files {
let shader_name = glsl.file_name().unwrap().to_str().unwrap();
// strip .glsl
Expand All @@ -27,9 +27,9 @@ fn write_shaders(glsl_files: Vec<PathBuf>, shader_file_path: &Path) {
write!(shader_file, " h.insert(\"{}\", include_str!(\"{}\"));\n",
shader_name, full_name).unwrap();
}
write!(shader_file, " h\n").unwrap();
write!(shader_file, " }};\n").unwrap();
write!(shader_file, "}}\n").unwrap();
write!(shader_file, " h\n").unwrap();
write!(shader_file, " }};\n").unwrap();
write!(shader_file, "}}\n").unwrap();
}

fn main() {
Expand Down
24 changes: 11 additions & 13 deletions webrender/src/clip_scroll_tree.rs
Expand Up @@ -3,19 +3,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use clip_scroll_node::{ClipScrollNode, NodeType, ScrollingState};
use fnv::FnvHasher;
use internal_types::{FastHashSet, FastHashMap};
use print_tree::PrintTree;
use std::collections::{HashMap, HashSet};
use std::hash::BuildHasherDefault;
use api::{ClipId, LayerPoint, LayerRect, LayerToScrollTransform};
use api::{LayerToWorldTransform, PipelineId, ScrollClamping, ScrollEventPhase};
use api::{LayerVector2D, ScrollLayerState, ScrollLocation, WorldPoint};

pub type ScrollStates = HashMap<ClipId, ScrollingState, BuildHasherDefault<FnvHasher>>;
pub type ScrollStates = FastHashMap<ClipId, ScrollingState>;

pub struct ClipScrollTree {
pub nodes: HashMap<ClipId, ClipScrollNode, BuildHasherDefault<FnvHasher>>,
pub pending_scroll_offsets: HashMap<ClipId, (LayerPoint, ScrollClamping)>,
pub nodes: FastHashMap<ClipId, ClipScrollNode>,
pub pending_scroll_offsets: FastHashMap<ClipId, (LayerPoint, ScrollClamping)>,

/// The ClipId of the currently scrolling node. Used to allow the same
/// node to scroll even if a touch operation leaves the boundaries of that node.
Expand All @@ -36,20 +34,20 @@ pub struct ClipScrollTree {

/// A set of pipelines which should be discarded the next time this
/// tree is drained.
pub pipelines_to_discard: HashSet<PipelineId>,
pub pipelines_to_discard: FastHashSet<PipelineId>,
}

impl ClipScrollTree {
pub fn new() -> ClipScrollTree {
let dummy_pipeline = PipelineId::dummy();
ClipScrollTree {
nodes: HashMap::default(),
pending_scroll_offsets: HashMap::new(),
nodes: FastHashMap::default(),
pending_scroll_offsets: FastHashMap::default(),
currently_scrolling_node_id: None,
root_reference_frame_id: ClipId::root_reference_frame(dummy_pipeline),
topmost_scrolling_node_id: ClipId::root_scroll_node(dummy_pipeline),
current_new_node_item: 1,
pipelines_to_discard: HashSet::new(),
pipelines_to_discard: FastHashSet::default(),
}
}

Expand All @@ -68,8 +66,8 @@ impl ClipScrollTree {
}

pub fn collect_nodes_bouncing_back(&self)
-> HashSet<ClipId, BuildHasherDefault<FnvHasher>> {
let mut nodes_bouncing_back = HashSet::default();
-> FastHashSet<ClipId> {
let mut nodes_bouncing_back = FastHashSet::default();
for (clip_id, node) in self.nodes.iter() {
if let NodeType::ScrollFrame(ref scrolling) = node.node_type {
if scrolling.bouncing_back {
Expand Down Expand Up @@ -123,7 +121,7 @@ impl ClipScrollTree {
pub fn drain(&mut self) -> ScrollStates {
self.current_new_node_item = 1;

let mut scroll_states = HashMap::default();
let mut scroll_states = FastHashMap::default();
for (layer_id, old_node) in &mut self.nodes.drain() {
if self.pipelines_to_discard.contains(&layer_id.pipeline_id()) {
continue;
Expand Down
17 changes: 7 additions & 10 deletions webrender/src/device.rs
Expand Up @@ -3,16 +3,13 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use euclid::Transform3D;
use fnv::FnvHasher;
use gleam::gl;
use internal_types::{PackedVertex, RenderTargetMode, TextureSampler, DEFAULT_TEXTURE};
use internal_types::{BlurAttribute, ClipAttribute, VertexAttribute};
use internal_types::{DebugFontVertex, DebugColorVertex};
use internal_types::{DebugFontVertex, DebugColorVertex, FastHashMap};
//use notify::{self, Watcher};
use super::shader_source;
use std::collections::HashMap;
use std::fs::File;
use std::hash::BuildHasherDefault;
use std::io::Read;
use std::iter::repeat;
use std::mem;
Expand Down Expand Up @@ -870,9 +867,9 @@ pub struct Device {

// resources
resource_override_path: Option<PathBuf>,
textures: HashMap<TextureId, Texture, BuildHasherDefault<FnvHasher>>,
programs: HashMap<ProgramId, Program, BuildHasherDefault<FnvHasher>>,
vaos: HashMap<VAOId, VAO, BuildHasherDefault<FnvHasher>>,
textures: FastHashMap<TextureId, Texture>,
programs: FastHashMap<ProgramId, Program>,
vaos: FastHashMap<VAOId, VAO>,

// misc.
shader_preamble: String,
Expand Down Expand Up @@ -923,9 +920,9 @@ impl Device {
default_read_fbo: 0,
default_draw_fbo: 0,

textures: HashMap::default(),
programs: HashMap::default(),
vaos: HashMap::default(),
textures: FastHashMap::default(),
programs: FastHashMap::default(),
vaos: FastHashMap::default(),

shader_preamble,

Expand Down
9 changes: 3 additions & 6 deletions webrender/src/frame.rs
Expand Up @@ -11,17 +11,14 @@ use api::{ScrollPolicy, ScrollSensitivity, SpecificDisplayItem, StackingContext,
use api::{TransformStyle, WorldPoint};
use clip_scroll_tree::{ClipScrollTree, ScrollStates};
use euclid::rect;
use fnv::FnvHasher;
use gpu_cache::GpuCache;
use internal_types::{RendererFrame};
use internal_types::{FastHashMap, RendererFrame};
use frame_builder::{FrameBuilder, FrameBuilderConfig};
use mask_cache::ClipRegion;
use profiler::{GpuCacheProfileCounters, TextureCacheProfileCounters};
use resource_cache::{ResourceCache, TiledImageMap};
use scene::{Scene, SceneProperties};
use std::cmp;
use std::collections::HashMap;
use std::hash::BuildHasherDefault;
use tiling::{CompositeOps, DisplayListMap, PrimitiveFlags};
use util::{ComplexClipRegionHelpers, subtract_rect};

Expand Down Expand Up @@ -177,7 +174,7 @@ impl<'a> FlattenContext<'a> {
// TODO: doc
pub struct Frame {
pub clip_scroll_tree: ClipScrollTree,
pub pipeline_epoch_map: HashMap<PipelineId, Epoch, BuildHasherDefault<FnvHasher>>,
pub pipeline_epoch_map: FastHashMap<PipelineId, Epoch>,
id: FrameId,
frame_builder_config: FrameBuilderConfig,
frame_builder: Option<FrameBuilder>,
Expand Down Expand Up @@ -222,7 +219,7 @@ impl StackingContextHelpers for StackingContext {
impl Frame {
pub fn new(config: FrameBuilderConfig) -> Frame {
Frame {
pipeline_epoch_map: HashMap::default(),
pipeline_epoch_map: FastHashMap::default(),
clip_scroll_tree: ClipScrollTree::new(),
id: FrameId(0),
frame_builder: None,
Expand Down
16 changes: 6 additions & 10 deletions webrender/src/frame_builder.rs
Expand Up @@ -10,10 +10,9 @@ use api::{LayerToScrollTransform, LayerVector2D, LayoutVector2D, LineOrientation
use api::{LocalClip, PipelineId, RepeatMode, ScrollSensitivity, TextShadow, TileOffset};
use api::{TransformStyle, WebGLContextId, WorldPixel, YuvColorSpace, YuvData};
use app_units::Au;
use fnv::FnvHasher;
use frame::FrameId;
use gpu_cache::GpuCache;
use internal_types::HardwareCompositeOp;
use internal_types::{FastHashMap, HardwareCompositeOp};
use mask_cache::{ClipMode, ClipRegion, ClipSource, MaskCacheInfo};
use plane_split::{BspSplitter, Polygon, Splitter};
use prim_store::{GradientPrimitiveCpu, ImagePrimitiveCpu, LinePrimitive, PrimitiveKind};
Expand All @@ -28,8 +27,6 @@ use resource_cache::ResourceCache;
use clip_scroll_node::{ClipInfo, ClipScrollNode, NodeType};
use clip_scroll_tree::ClipScrollTree;
use std::{cmp, f32, i32, mem, usize};
use std::collections::HashMap;
use std::hash::BuildHasherDefault;
use euclid::{SideOffsets2D, vec2, vec3};
use tiling::{ContextIsolation, StackingContextIndex};
use tiling::{ClipScrollGroup, ClipScrollGroupIndex, CompositeOps, DisplayListMap, Frame};
Expand Down Expand Up @@ -118,9 +115,8 @@ pub struct FrameBuilder {

stacking_context_store: Vec<StackingContext>,
clip_scroll_group_store: Vec<ClipScrollGroup>,
clip_scroll_group_indices: HashMap<ClipAndScrollInfo,
ClipScrollGroupIndex,
BuildHasherDefault<FnvHasher>>,
clip_scroll_group_indices: FastHashMap<ClipAndScrollInfo,
ClipScrollGroupIndex>,
packed_layers: Vec<PackedLayer>,

// A stack of the current text-shadow primitives.
Expand Down Expand Up @@ -151,7 +147,7 @@ impl FrameBuilder {
FrameBuilder {
stacking_context_store: recycle_vec(prev.stacking_context_store),
clip_scroll_group_store: recycle_vec(prev.clip_scroll_group_store),
clip_scroll_group_indices: HashMap::default(),
clip_scroll_group_indices: FastHashMap::default(),
cmds: recycle_vec(prev.cmds),
packed_layers: recycle_vec(prev.packed_layers),
shadow_prim_stack: recycle_vec(prev.shadow_prim_stack),
Expand All @@ -169,7 +165,7 @@ impl FrameBuilder {
FrameBuilder {
stacking_context_store: Vec::new(),
clip_scroll_group_store: Vec::new(),
clip_scroll_group_indices: HashMap::default(),
clip_scroll_group_indices: FastHashMap::default(),
cmds: Vec::new(),
packed_layers: Vec::new(),
shadow_prim_stack: Vec::new(),
Expand Down Expand Up @@ -1370,7 +1366,7 @@ impl FrameBuilder {
// The stacking contexts that fall into this category are
// - ones with `ContextIsolation::Items`, for their actual items to be backed
// - immediate children of `ContextIsolation::Items`
let mut preserve_3d_map: HashMap<StackingContextIndex, RenderTask> = HashMap::new();
let mut preserve_3d_map: FastHashMap<StackingContextIndex, RenderTask> = FastHashMap::default();
// The plane splitter stack, using a simple BSP tree.
let mut splitter_stack = Vec::new();

Expand Down
14 changes: 6 additions & 8 deletions webrender/src/glyph_rasterizer.rs
Expand Up @@ -5,18 +5,16 @@
#[cfg(test)]
use app_units::Au;
use device::TextureFilter;
use fnv::FnvHasher;
use frame::FrameId;
use internal_types::FastHashSet;
use platform::font::{FontContext, RasterizedGlyph};
use profiler::TextureCacheProfileCounters;
use rayon::ThreadPool;
use rayon::prelude::*;
use resource_cache::ResourceClassCache;
use std::hash::BuildHasherDefault;
use std::sync::{Arc, Mutex, MutexGuard};
use std::sync::mpsc::{channel, Receiver, Sender};
use std::collections::hash_map::Entry;
use std::collections::HashSet;
use std::mem;
use texture_cache::{TextureCacheItemId, TextureCache};
#[cfg(test)]
Expand Down Expand Up @@ -89,7 +87,7 @@ pub struct GlyphRasterizer {
// because the glyph cache hash table is not updated
// until the end of the frame when we wait for glyph requests
// to be resolved.
pending_glyphs: HashSet<GlyphRequest>,
pending_glyphs: FastHashSet<GlyphRequest>,

// We defer removing fonts to the end of the frame so that:
// - this work is done outside of the critical path,
Expand Down Expand Up @@ -119,7 +117,7 @@ impl GlyphRasterizer {
),
glyph_rx,
glyph_tx,
pending_glyphs: HashSet::new(),
pending_glyphs: FastHashSet::default(),
workers,
fonts_to_remove: Vec::new(),
}
Expand Down Expand Up @@ -152,7 +150,7 @@ impl GlyphRasterizer {
current_frame_id: FrameId,
font: FontInstanceKey,
glyph_instances: &[GlyphInstance],
requested_items: &mut HashSet<TextureCacheItemId, BuildHasherDefault<FnvHasher>>,
requested_items: &mut FastHashSet<TextureCacheItemId>,
) {
assert!(self.font_contexts.lock_shared_context().has_font(&font.font_key));

Expand Down Expand Up @@ -225,7 +223,7 @@ impl GlyphRasterizer {
current_frame_id: FrameId,
glyph_cache: &mut GlyphCache,
texture_cache: &mut TextureCache,
requested_items: &mut HashSet<TextureCacheItemId, BuildHasherDefault<FnvHasher>>,
requested_items: &mut FastHashSet<TextureCacheItemId>,
texture_cache_profile: &mut TextureCacheProfileCounters,
) {
let mut rasterized_glyphs = Vec::with_capacity(self.pending_glyphs.len());
Expand Down Expand Up @@ -348,7 +346,7 @@ fn raterize_200_glyphs() {
let workers = Arc::new(ThreadPool::new(Configuration::new()).unwrap());
let mut glyph_rasterizer = GlyphRasterizer::new(workers);
let mut glyph_cache = GlyphCache::new();
let mut requested_items = HashSet::default();
let mut requested_items = FastHashSet::default();

let mut font_file = File::open("../wrench/reftests/text/VeraBd.ttf").expect("Couldn't open font file");
let mut font_data = vec![];
Expand Down
13 changes: 8 additions & 5 deletions webrender/src/internal_types.rs
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use device::TextureFilter;
use fnv::FnvHasher;
use fxhash::FxHasher;
use profiler::BackendProfileCounters;
use std::collections::{HashMap, HashSet};
use std::f32;
Expand All @@ -17,6 +17,9 @@ use api::{ClipId, ColorU, DevicePoint, DeviceUintRect, DocumentId, Epoch};
use api::{ExternalImageData, ExternalImageId};
use api::{ImageData, ImageFormat, PipelineId};

pub type FastHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
pub type FastHashSet<K> = HashSet<K, BuildHasherDefault<FxHasher>>;

// An ID for a texture that is owned by the
// texture cache module. This can include atlases
// or standalone textures allocated via the
Expand Down Expand Up @@ -242,16 +245,16 @@ pub struct RendererFrame {
/// The last rendered epoch for each pipeline present in the frame.
/// This information is used to know if a certain transformation on the layout has
/// been rendered, which is necessary for reftests.
pub pipeline_epoch_map: HashMap<PipelineId, Epoch, BuildHasherDefault<FnvHasher>>,
pub pipeline_epoch_map: FastHashMap<PipelineId, Epoch>,
/// The layers that are currently affected by the over-scrolling animation.
pub layers_bouncing_back: HashSet<ClipId, BuildHasherDefault<FnvHasher>>,
pub layers_bouncing_back: FastHashSet<ClipId>,

pub frame: Option<tiling::Frame>,
}

impl RendererFrame {
pub fn new(pipeline_epoch_map: HashMap<PipelineId, Epoch, BuildHasherDefault<FnvHasher>>,
layers_bouncing_back: HashSet<ClipId, BuildHasherDefault<FnvHasher>>,
pub fn new(pipeline_epoch_map: FastHashMap<PipelineId, Epoch>,
layers_bouncing_back: FastHashSet<ClipId>,
frame: Option<tiling::Frame>)
-> RendererFrame {
RendererFrame {
Expand Down
2 changes: 1 addition & 1 deletion webrender/src/lib.rs
Expand Up @@ -132,7 +132,7 @@ extern crate dwrote;
extern crate app_units;
extern crate bincode;
extern crate euclid;
extern crate fnv;
extern crate fxhash;
extern crate gleam;
extern crate num_traits;
//extern crate notify;
Expand Down