Skip to content

Commit

Permalink
Add a profile_traits crate to reduce compile times.
Browse files Browse the repository at this point in the history
A rebuild after touching components/profile/mem.rs now takes 48 seconds (and
only rebuilds `profile` and `servo`) which is much lower than it used to be.
In comparison, a rebuild after touching components/profile_traits/mem.rs takes
294 seconds and rebuilds many more crates.

This change also removes some unnecessary crate dependencies in `net` and
`net_traits`.
  • Loading branch information
nnethercote committed May 1, 2015
1 parent 826b722 commit 092507d
Show file tree
Hide file tree
Showing 37 changed files with 269 additions and 225 deletions.
4 changes: 2 additions & 2 deletions components/compositing/Cargo.toml
Expand Up @@ -22,8 +22,8 @@ path = "../msg"
[dependencies.net]
path = "../net"

[dependencies.profile]
path = "../profile"
[dependencies.profile_traits]
path = "../profile_traits"

[dependencies.net_traits]
path = "../net_traits"
Expand Down
4 changes: 2 additions & 2 deletions components/compositing/compositor.rs
Expand Up @@ -32,8 +32,8 @@ use msg::constellation_msg::{ConstellationChan, NavigationDirection};
use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData};
use msg::constellation_msg::{PipelineId, WindowSizeData};
use png;
use profile::mem;
use profile::time::{self, ProfilerCategory, profile};
use profile_traits::mem;
use profile_traits::time::{self, ProfilerCategory, profile};
use script_traits::{ConstellationControlMsg, ScriptControlChan};
use std::cmp;
use std::collections::HashMap;
Expand Down
4 changes: 2 additions & 2 deletions components/compositing/compositor_task.rs
Expand Up @@ -21,8 +21,8 @@ use msg::compositor_msg::{Epoch, LayerId, LayerMetadata, ReadyState};
use msg::compositor_msg::{PaintListener, PaintState, ScriptListener, ScrollPolicy};
use msg::constellation_msg::{ConstellationChan, PipelineId};
use msg::constellation_msg::{Key, KeyState, KeyModifiers};
use profile::mem;
use profile::time;
use profile_traits::mem;
use profile_traits::time;
use std::sync::mpsc::{channel, Sender, Receiver};
use std::fmt::{Error, Formatter, Debug};
use std::rc::Rc;
Expand Down
4 changes: 2 additions & 2 deletions components/compositing/constellation.rs
Expand Up @@ -23,8 +23,8 @@ use msg::constellation_msg::{self, ConstellationChan, Failure};
use net_traits::{self, ResourceTask};
use net_traits::image_cache_task::ImageCacheTask;
use net_traits::storage_task::{StorageTask, StorageTaskMsg};
use profile::mem;
use profile::time;
use profile_traits::mem;
use profile_traits::time;
use script_traits::{CompositorEvent, ConstellationControlMsg};
use script_traits::{ScriptControlChan, ScriptTaskFactory};
use std::borrow::ToOwned;
Expand Down
4 changes: 2 additions & 2 deletions components/compositing/headless.rs
Expand Up @@ -9,8 +9,8 @@ use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D;
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, WindowSizeData};
use profile::mem;
use profile::time;
use profile_traits::mem;
use profile_traits::time;

/// Starts the compositor, which listens for messages on the specified port.
///
Expand Down
2 changes: 1 addition & 1 deletion components/compositing/lib.rs
Expand Up @@ -22,7 +22,7 @@ extern crate png;
extern crate script_traits;
extern crate msg;
extern crate net;
extern crate profile;
extern crate profile_traits;
extern crate net_traits;
#[macro_use]
extern crate util;
Expand Down
4 changes: 2 additions & 2 deletions components/compositing/pipeline.rs
Expand Up @@ -16,8 +16,8 @@ use gfx::font_cache_task::FontCacheTask;
use layers::geometry::DevicePixel;
use msg::constellation_msg::{ConstellationChan, Failure, FrameId, PipelineId, SubpageId};
use msg::constellation_msg::{LoadData, WindowSizeData, PipelineExitType, MozBrowserEvent};
use profile::mem;
use profile::time;
use profile_traits::mem;
use profile_traits::time;
use net_traits::ResourceTask;
use net_traits::image_cache_task::ImageCacheTask;
use net_traits::storage_task::StorageTask;
Expand Down
4 changes: 2 additions & 2 deletions components/gfx/Cargo.toml
Expand Up @@ -20,8 +20,8 @@ path = "../util"
[dependencies.msg]
path = "../msg"

[dependencies.profile]
path = "../profile"
[dependencies.profile_traits]
path = "../profile_traits"

[dependencies.style]
path = "../style"
Expand Down
2 changes: 1 addition & 1 deletion components/gfx/lib.rs
Expand Up @@ -26,7 +26,7 @@ extern crate layers;
extern crate libc;
extern crate stb_image;
extern crate png;
extern crate profile;
extern crate profile_traits;
extern crate script_traits;
extern crate "rustc-serialize" as rustc_serialize;
extern crate unicode;
Expand Down
2 changes: 1 addition & 1 deletion components/gfx/paint_task.rs
Expand Up @@ -25,7 +25,7 @@ use msg::compositor_msg::{LayerMetadata, PaintListener, ScrollPolicy};
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId};
use msg::constellation_msg::PipelineExitType;
use profile::time::{self, profile};
use profile_traits::time::{self, profile};
use skia::SkiaGrGLNativeContextRef;
use std::borrow::ToOwned;
use std::mem;
Expand Down
4 changes: 2 additions & 2 deletions components/layout/Cargo.toml
Expand Up @@ -37,8 +37,8 @@ path = "../plugins"
[dependencies.net_traits]
path = "../net_traits"

[dependencies.profile]
path = "../profile"
[dependencies.profile_traits]
path = "../profile_traits"

[dependencies.util]
path = "../util"
Expand Down
6 changes: 3 additions & 3 deletions components/layout/layout_task.rs
Expand Up @@ -42,9 +42,9 @@ use log;
use msg::compositor_msg::ScrollPolicy;
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, Failure, PipelineExitType, PipelineId};
use profile::mem::{self, Report, ReportsChan};
use profile::time::{self, ProfilerMetadata, profile};
use profile::time::{TimerMetadataFrameType, TimerMetadataReflowType};
use profile_traits::mem::{self, Report, ReportsChan};
use profile_traits::time::{self, ProfilerMetadata, profile};
use profile_traits::time::{TimerMetadataFrameType, TimerMetadataReflowType};
use net_traits::{load_bytes_iter, ResourceTask};
use net_traits::image_cache_task::{ImageCacheTask, ImageCacheResult, ImageCacheChan};
use script::dom::bindings::js::LayoutJS;
Expand Down
2 changes: 1 addition & 1 deletion components/layout/lib.rs
Expand Up @@ -32,7 +32,7 @@ extern crate bitflags;
extern crate "plugins" as servo_plugins;
extern crate net_traits;
#[macro_use]
extern crate profile;
extern crate profile_traits;

#[macro_use]
extern crate util;
Expand Down
2 changes: 1 addition & 1 deletion components/layout/parallel.rs
Expand Up @@ -20,7 +20,7 @@ use wrapper::{layout_node_to_unsafe_layout_node, layout_node_from_unsafe_layout_
use wrapper::{PostorderNodeMutTraversal, UnsafeLayoutNode};
use wrapper::{PreorderDomTraversal, PostorderDomTraversal};

use profile::time::{self, ProfilerMetadata, profile};
use profile_traits::time::{self, ProfilerMetadata, profile};
use std::mem;
use std::ptr;
use std::sync::atomic::{AtomicIsize, Ordering};
Expand Down
4 changes: 2 additions & 2 deletions components/layout_traits/Cargo.toml
Expand Up @@ -19,8 +19,8 @@ path = "../msg"
[dependencies.net_traits]
path = "../net_traits"

[dependencies.profile]
path = "../profile"
[dependencies.profile_traits]
path = "../profile_traits"

[dependencies.util]
path = "../util"
Expand Down
6 changes: 3 additions & 3 deletions components/layout_traits/lib.rs
Expand Up @@ -5,7 +5,7 @@
extern crate gfx;
extern crate script_traits;
extern crate msg;
extern crate profile;
extern crate profile_traits;
extern crate net_traits;
extern crate url;
extern crate util;
Expand All @@ -18,8 +18,8 @@ extern crate util;
use gfx::font_cache_task::FontCacheTask;
use gfx::paint_task::PaintChan;
use msg::constellation_msg::{ConstellationChan, Failure, PipelineId, PipelineExitType};
use profile::mem;
use profile::time;
use profile_traits::mem;
use profile_traits::time;
use net_traits::ResourceTask;
use net_traits::image_cache_task::ImageCacheTask;
use url::Url;
Expand Down
3 changes: 0 additions & 3 deletions components/net/Cargo.toml
Expand Up @@ -7,9 +7,6 @@ authors = ["The Servo Project Developers"]
name = "net"
path = "lib.rs"

[dependencies.profile]
path = "../profile"

[dependencies.net_traits]
path = "../net_traits"

Expand Down
1 change: 0 additions & 1 deletion components/net/lib.rs
Expand Up @@ -27,7 +27,6 @@ extern crate png;
#[macro_use]
extern crate log;
extern crate openssl;
extern crate profile;
extern crate "rustc-serialize" as rustc_serialize;
extern crate util;
extern crate time;
Expand Down
3 changes: 0 additions & 3 deletions components/net_traits/Cargo.toml
Expand Up @@ -13,9 +13,6 @@ git = "https://github.com/servo/rust-geom"
[dependencies.png]
git = "https://github.com/servo/rust-png"

[dependencies.profile]
path = "../profile"

[dependencies.util]
path = "../util"

Expand Down
1 change: 0 additions & 1 deletion components/net_traits/lib.rs
Expand Up @@ -12,7 +12,6 @@ extern crate hyper;
#[macro_use]
extern crate log;
extern crate png;
extern crate profile;
extern crate stb_image;
extern crate url;
extern crate util;
Expand Down
4 changes: 3 additions & 1 deletion components/profile/Cargo.toml
Expand Up @@ -7,6 +7,9 @@ authors = ["The Servo Project Developers"]
name = "profile"
path = "lib.rs"

[dependencies.profile_traits]
path = "../profile_traits"

[dependencies.task_info]
path = "../../support/rust-task_info"

Expand All @@ -17,4 +20,3 @@ path = "../util"
libc = "*"
regex = "0.1.14"
time = "0.1.12"
url = "0.2.16"
3 changes: 2 additions & 1 deletion components/profile/lib.rs
Expand Up @@ -16,13 +16,14 @@

extern crate collections;
extern crate libc;
#[macro_use]
extern crate profile_traits;
#[cfg(target_os="linux")]
extern crate regex;
#[cfg(target_os="macos")]
extern crate task_info;
extern crate "time" as std_time;
extern crate util;
extern crate url;

pub mod mem;
pub mod time;
73 changes: 3 additions & 70 deletions components/profile/mem.rs
Expand Up @@ -4,83 +4,16 @@

//! Memory profiling functions.

use profile_traits::mem::{ProfilerChan, ProfilerMsg, Reporter, ReportsChan};
use self::system_reporter::SystemReporter;
use std::borrow::ToOwned;
use std::cmp::Ordering;
use std::collections::HashMap;
use std::old_io::timer::sleep;
use std::sync::mpsc::{Sender, channel, Receiver};
use std::sync::mpsc::{channel, Receiver};
use std::time::duration::Duration;
use util::task::spawn_named;

#[derive(Clone)]
pub struct ProfilerChan(pub Sender<ProfilerMsg>);

impl ProfilerChan {
pub fn send(&self, msg: ProfilerMsg) {
let ProfilerChan(ref c) = *self;
c.send(msg).unwrap();
}
}

/// An easy way to build a path for a report.
#[macro_export]
macro_rules! path {
($($x:expr),*) => {{
use std::borrow::ToOwned;
vec![$( $x.to_owned() ),*]
}}
}

/// A single memory-related measurement.
pub struct Report {
/// The identifying path for this report.
pub path: Vec<String>,

/// The size, in bytes.
pub size: usize,
}

/// A channel through which memory reports can be sent.
#[derive(Clone)]
pub struct ReportsChan(pub Sender<Vec<Report>>);

impl ReportsChan {
pub fn send(&self, report: Vec<Report>) {
let ReportsChan(ref c) = *self;
c.send(report).unwrap();
}
}

/// A memory reporter is capable of measuring some data structure of interest. Because it needs
/// to be passed to and registered with the Profiler, it's typically a "small" (i.e. easily
/// cloneable) value that provides access to a "large" data structure, e.g. a channel that can
/// inject a request for measurements into the event queue associated with the "large" data
/// structure.
pub trait Reporter {
/// Collect one or more memory reports. Returns true on success, and false on failure.
fn collect_reports(&self, reports_chan: ReportsChan) -> bool;
}

/// Messages that can be sent to the memory profiler thread.
pub enum ProfilerMsg {
/// Register a Reporter with the memory profiler. The String is only used to identify the
/// reporter so it can be unregistered later. The String must be distinct from that used by any
/// other registered reporter otherwise a panic will occur.
RegisterReporter(String, Box<Reporter + Send>),

/// Unregister a Reporter with the memory profiler. The String must match the name given when
/// the reporter was registered. If the String does not match the name of a registered reporter
/// a panic will occur.
UnregisterReporter(String),

/// Triggers printing of the memory profiling metrics.
Print,

/// Tells the memory profiler to shut down.
Exit,
}

pub struct Profiler {
/// The port through which messages are received.
pub port: Receiver<ProfilerMsg>,
Expand Down Expand Up @@ -363,11 +296,11 @@ impl ReportsForest {

mod system_reporter {
use libc::{c_char, c_int, c_void, size_t};
use profile_traits::mem::{Report, Reporter, ReportsChan};
use std::borrow::ToOwned;
use std::ffi::CString;
use std::mem::size_of;
use std::ptr::null_mut;
use super::{Report, Reporter, ReportsChan};
#[cfg(target_os="macos")]
use task_info::task_basic_info::{virtual_size, resident_size};

Expand Down

0 comments on commit 092507d

Please sign in to comment.