|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
11 |
| -//! A crate for measuring the heap usage of data structures in a way that |
12 |
| -//! integrates with Firefox's memory reporting, particularly the use of |
13 |
| -//! mozjemalloc and DMD. In particular, it has the following features. |
| 11 | +//! A an allocator-agnostic crate for measuring the runtime size of a value |
| 12 | +//! including the size of any heap allocations that are owned by that value. |
| 13 | +//! |
| 14 | +//! - The core abstraction is provided by the [`MallocSizeOf`] trait which should be implemented for all |
| 15 | +//! types whose size you wish to measure. |
| 16 | +//! - A derive macro for implementing this trait on structs is provided by the [malloc_size_of_derive](https://docs.rs/malloc_size_of_derive) crate |
| 17 | +//! - Additionally there are [`MallocUnconditionalSizeOf`], [`MallocConditionalSizeOf`] traits for measuring |
| 18 | +//! types where ownership is shared (such as `Arc` and `Rc`). |
| 19 | +//! - Each of these traits also has a "shallow" variant ([`MallocShallowSizeOf`], [`MallocUnconditionalShallowSizeOf`], and [`MallocConditionalShallowSizeOf`]) which only measure the heap size of the value passed |
| 20 | +//! and not any nested allocations. |
| 21 | +//! |
| 22 | +//! All of these traits rely on being provided with an instance of [`MallocSizeOfOps`] which allows size computations |
| 23 | +//! to call into the allocator to ask it for the underlyinhg size of the allocations backing data structures. |
| 24 | +//! |
| 25 | +//! This crate is used by both Servo and Firefox for memory usage calculation. |
| 26 | +//! |
| 27 | +//! ## Features |
| 28 | +//! |
14 | 29 | //! - It isn't bound to a particular heap allocator.
|
15 | 30 | //! - It provides traits for both "shallow" and "deep" measurement, which gives
|
16 | 31 | //! flexibility in the cases where the traits can't be used.
|
17 | 32 | //! - It allows for measuring blocks even when only an interior pointer can be
|
18 | 33 | //! obtained for heap allocations, e.g. `HashSet` and `HashMap`. (This relies
|
19 |
| -//! on the heap allocator having suitable support, which mozjemalloc has.) |
| 34 | +//! on the heap allocator having suitable support, which `jemalloc` has.) |
20 | 35 | //! - It allows handling of types like `Rc` and `Arc` by providing traits that
|
21 | 36 | //! are different to the ones for non-graph structures.
|
22 | 37 | //!
|
23 |
| -//! Suggested uses are as follows. |
| 38 | +//! ## Suggested usage |
| 39 | +//! |
24 | 40 | //! - When possible, use the `MallocSizeOf` trait. (Deriving support is
|
25 | 41 | //! provided by the `malloc_size_of_derive` crate.)
|
26 | 42 | //! - If you need an additional synchronization argument, provide a function
|
|
42 | 58 | //! fields in structs, because it makes it clear that the Box is being
|
43 | 59 | //! measured as well as the thing it points to. E.g.
|
44 | 60 | //! `<Box<_> as MallocSizeOf>::size_of(field, ops)`.
|
45 |
| -//! |
46 |
| -//! Note: WebRender has a reduced fork of this crate, so that we can avoid |
47 |
| -//! publishing this crate on crates.io. |
48 | 61 | #![cfg_attr(not(feature = "std"), no_std)]
|
49 | 62 | extern crate alloc;
|
50 | 63 | mod impls;
|
|
0 commit comments