mirror of
https://github.com/emilk/egui.git
synced 2026-09-03 15:20:05 -04:00
Use mimalloc for benchmarks (#7029)
`mimalloc` is a _much_ faster allocator, especially important when doing a lot of small allocations (which egui does). We use `mimalloc` in Rerun, and I recommend everyone to use it. ## The difference it makes 
This commit is contained in:
@@ -400,6 +400,9 @@
|
||||
//! profile-with-puffin = ["profiling/profile-with-puffin"]
|
||||
//! ```
|
||||
//!
|
||||
//! ## Custom allocator
|
||||
//! egui apps can run significantly (~20%) faster by using a custom allocator, like [mimalloc](https://crates.io/crates/mimalloc) or [talc](https://crates.io/crates/talc).
|
||||
//!
|
||||
|
||||
#![allow(clippy::float_cmp)]
|
||||
#![allow(clippy::manual_range_contains)]
|
||||
|
||||
@@ -86,6 +86,7 @@ env_logger = { version = "0.10", default-features = false, features = [
|
||||
"auto-color",
|
||||
"humantime",
|
||||
] }
|
||||
mimalloc.workspace = true
|
||||
rfd = { version = "0.15.3", optional = true }
|
||||
|
||||
# web:
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
#![allow(rustdoc::missing_crate_level_docs)] // it's an example
|
||||
#![allow(clippy::never_loop)] // False positive
|
||||
|
||||
#[global_allocator]
|
||||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; // Much faster allocator, can give 20% speedups: https://github.com/emilk/egui/pull/7029
|
||||
|
||||
// When compiling natively:
|
||||
fn main() -> eframe::Result {
|
||||
for arg in std::env::args().skip(1) {
|
||||
|
||||
@@ -56,8 +56,9 @@ serde = { workspace = true, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion.workspace = true
|
||||
egui_kittest = { workspace = true, features = ["wgpu", "snapshot"] }
|
||||
egui = { workspace = true, features = ["default_fonts"] }
|
||||
egui_kittest = { workspace = true, features = ["wgpu", "snapshot"] }
|
||||
mimalloc.workspace = true # for benchmarks
|
||||
rand = "0.9"
|
||||
|
||||
[[bench]]
|
||||
|
||||
@@ -8,6 +8,9 @@ use egui::{Button, Id, RichText, TextureId, Ui, UiBuilder, Vec2};
|
||||
use egui_demo_lib::LOREM_IPSUM_LONG;
|
||||
use rand::Rng as _;
|
||||
|
||||
#[global_allocator]
|
||||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; // Much faster allocator
|
||||
|
||||
/// Each iteration should be called in their own `Ui` with an intentional id clash,
|
||||
/// to prevent the Context from building a massive map of `WidgetRects` (which would slow the test,
|
||||
/// causing unreliable results).
|
||||
|
||||
@@ -101,6 +101,7 @@ backtrace = { workspace = true, optional = true }
|
||||
|
||||
[dev-dependencies]
|
||||
criterion.workspace = true
|
||||
mimalloc.workspace = true
|
||||
similar-asserts.workspace = true
|
||||
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ use epaint::{
|
||||
TessellationOptions, Tessellator, TextureAtlas, Vec2,
|
||||
};
|
||||
|
||||
#[global_allocator]
|
||||
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; // Much faster allocator
|
||||
|
||||
fn single_dashed_lines(c: &mut Criterion) {
|
||||
c.bench_function("single_dashed_lines", move |b| {
|
||||
b.iter(|| {
|
||||
|
||||
Reference in New Issue
Block a user