2020-05-20 19:20:39 +00:00
|
|
|
use criterion::{criterion_group, criterion_main, Criterion};
|
|
|
|
|
2021-09-05 07:06:53 +00:00
|
|
|
use egui::epaint::TextShape;
|
2021-02-08 21:53:31 +00:00
|
|
|
use egui_demo_lib::LOREM_IPSUM_LONG;
|
|
|
|
|
2020-05-20 19:20:39 +00:00
|
|
|
pub fn criterion_benchmark(c: &mut Criterion) {
|
2022-01-10 22:13:10 +00:00
|
|
|
use egui::RawInput;
|
2020-05-20 19:20:39 +00:00
|
|
|
|
2020-09-09 10:41:59 +00:00
|
|
|
{
|
2022-01-10 22:13:10 +00:00
|
|
|
let ctx = egui::Context::default();
|
2020-12-29 12:40:11 +00:00
|
|
|
let mut demo_windows = egui_demo_lib::DemoWindows::default();
|
2020-09-09 10:41:59 +00:00
|
|
|
|
2021-03-29 20:48:13 +00:00
|
|
|
// The most end-to-end benchmark.
|
2021-09-03 19:07:25 +00:00
|
|
|
c.bench_function("demo_with_tessellate__realistic", |b| {
|
2021-03-29 20:48:13 +00:00
|
|
|
b.iter(|| {
|
2022-02-22 16:13:53 +00:00
|
|
|
let full_output = ctx.run(RawInput::default(), |ctx| {
|
2021-11-03 19:11:25 +00:00
|
|
|
demo_windows.ui(ctx);
|
|
|
|
});
|
2022-02-22 16:13:53 +00:00
|
|
|
ctx.tessellate(full_output.shapes)
|
2022-03-21 20:48:35 +00:00
|
|
|
});
|
2021-03-29 20:48:13 +00:00
|
|
|
});
|
|
|
|
|
2021-09-03 19:07:25 +00:00
|
|
|
c.bench_function("demo_no_tessellate", |b| {
|
2020-10-10 04:57:56 +00:00
|
|
|
b.iter(|| {
|
2022-01-10 22:13:10 +00:00
|
|
|
ctx.run(RawInput::default(), |ctx| {
|
2021-11-03 19:11:25 +00:00
|
|
|
demo_windows.ui(ctx);
|
|
|
|
})
|
2022-03-21 20:48:35 +00:00
|
|
|
});
|
2020-10-10 04:57:56 +00:00
|
|
|
});
|
2021-04-01 19:42:45 +00:00
|
|
|
|
2022-02-22 16:13:53 +00:00
|
|
|
let full_output = ctx.run(RawInput::default(), |ctx| {
|
2021-11-03 19:11:25 +00:00
|
|
|
demo_windows.ui(ctx);
|
|
|
|
});
|
2021-04-01 19:42:45 +00:00
|
|
|
c.bench_function("demo_only_tessellate", |b| {
|
2022-03-21 20:48:35 +00:00
|
|
|
b.iter(|| ctx.tessellate(full_output.shapes.clone()));
|
2021-04-01 19:42:45 +00:00
|
|
|
});
|
2020-10-10 04:57:56 +00:00
|
|
|
}
|
|
|
|
|
2021-04-01 19:42:45 +00:00
|
|
|
if false {
|
2022-01-10 22:13:10 +00:00
|
|
|
let ctx = egui::Context::default();
|
2023-01-25 09:24:23 +00:00
|
|
|
ctx.memory_mut(|m| m.set_everything_is_visible(true)); // give us everything
|
2020-12-29 12:40:11 +00:00
|
|
|
let mut demo_windows = egui_demo_lib::DemoWindows::default();
|
2021-09-03 19:07:25 +00:00
|
|
|
c.bench_function("demo_full_no_tessellate", |b| {
|
2020-09-09 10:41:59 +00:00
|
|
|
b.iter(|| {
|
2022-01-10 22:13:10 +00:00
|
|
|
ctx.run(RawInput::default(), |ctx| {
|
2021-11-03 19:11:25 +00:00
|
|
|
demo_windows.ui(ctx);
|
|
|
|
})
|
2022-03-21 20:48:35 +00:00
|
|
|
});
|
2020-09-09 10:41:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-18 08:24:31 +00:00
|
|
|
{
|
2022-01-10 22:13:10 +00:00
|
|
|
let ctx = egui::Context::default();
|
|
|
|
let _ = ctx.run(RawInput::default(), |ctx| {
|
2021-11-03 19:11:25 +00:00
|
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
|
|
|
c.bench_function("label &str", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
ui.label("the quick brown fox jumps over the lazy dog");
|
2022-03-21 20:48:35 +00:00
|
|
|
});
|
2021-11-03 19:11:25 +00:00
|
|
|
});
|
|
|
|
c.bench_function("label format!", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
ui.label("the quick brown fox jumps over the lazy dog".to_owned());
|
2022-03-21 20:48:35 +00:00
|
|
|
});
|
2021-11-03 19:11:25 +00:00
|
|
|
});
|
|
|
|
});
|
2021-04-18 08:24:31 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-10 22:13:10 +00:00
|
|
|
{
|
|
|
|
let ctx = egui::Context::default();
|
|
|
|
ctx.begin_frame(RawInput::default());
|
|
|
|
|
|
|
|
egui::CentralPanel::default().show(&ctx, |ui| {
|
|
|
|
c.bench_function("Painter::rect", |b| {
|
|
|
|
let painter = ui.painter();
|
|
|
|
let rect = ui.max_rect();
|
|
|
|
b.iter(|| {
|
|
|
|
painter.rect(rect, 2.0, egui::Color32::RED, (1.0, egui::Color32::WHITE));
|
2022-03-21 20:48:35 +00:00
|
|
|
});
|
2022-01-10 22:13:10 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Don't call `end_frame` to not have to drain the huge paint list
|
|
|
|
}
|
|
|
|
|
2021-02-08 21:53:31 +00:00
|
|
|
{
|
|
|
|
let pixels_per_point = 1.0;
|
2022-01-24 13:32:36 +00:00
|
|
|
let max_texture_side = 8 * 1024;
|
2021-02-08 21:53:31 +00:00
|
|
|
let wrap_width = 512.0;
|
2022-01-24 13:32:36 +00:00
|
|
|
let font_id = egui::FontId::default();
|
New text layout (#682)
This PR introduces a completely rewritten text layout engine which is simpler and more powerful. It allows mixing different text styles (heading, body, etc) and formats (color, underlining, strikethrough, …) in the same layout pass, and baked into the same `Galley`.
This opens up the door to having a syntax-highlighed code editor, or a WYSIWYG markdown editor.
One major change is the color is now baked in at layout time. However, many widgets changes text color on hovered. But we need to do the text layout before we know if it is hovered. Therefor the painter has an option to override the text color of a galley.
## Performance
Text layout alone is about 20% slower, but a lot of that is because more tessellation is done upfront. Text tessellation is now a lot faster, but text layout + tessellation still lands at a net loss of 5-10% in performance. There are however a few tricks to speed it up (like using `smallvec`) which I am saving for later. Text layout is also cached, meaning that in most cases (when all text isn't changing each frame) text tessellation is actually more important (and that's more than 2x faster!).
Sadly, the actual text cache lookup is significantly slower (300ns -> 600ns). That's because the `TextLayoutJob` is a lot bigger (it has more options, like underlining, fonts etc), so it is slower to hash and compare. I have an idea how to speed this up, but I need to do some other work before I can implement that.
All in all, the performance impact on `demo_with_tesselate__realistic` is about 5-6% in the red. Not great; not terrible. The benefits are worth it, but I also think with some work I can get that down significantly, hopefully down to the old levels.
2021-09-03 16:18:00 +00:00
|
|
|
let color = egui::Color32::WHITE;
|
2022-01-24 13:32:36 +00:00
|
|
|
let fonts = egui::epaint::text::Fonts::new(
|
|
|
|
pixels_per_point,
|
|
|
|
max_texture_side,
|
|
|
|
egui::FontDefinitions::default(),
|
|
|
|
);
|
|
|
|
{
|
|
|
|
let mut locked_fonts = fonts.lock();
|
|
|
|
c.bench_function("text_layout_uncached", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
use egui::epaint::text::{layout, LayoutJob};
|
New text layout (#682)
This PR introduces a completely rewritten text layout engine which is simpler and more powerful. It allows mixing different text styles (heading, body, etc) and formats (color, underlining, strikethrough, …) in the same layout pass, and baked into the same `Galley`.
This opens up the door to having a syntax-highlighed code editor, or a WYSIWYG markdown editor.
One major change is the color is now baked in at layout time. However, many widgets changes text color on hovered. But we need to do the text layout before we know if it is hovered. Therefor the painter has an option to override the text color of a galley.
## Performance
Text layout alone is about 20% slower, but a lot of that is because more tessellation is done upfront. Text tessellation is now a lot faster, but text layout + tessellation still lands at a net loss of 5-10% in performance. There are however a few tricks to speed it up (like using `smallvec`) which I am saving for later. Text layout is also cached, meaning that in most cases (when all text isn't changing each frame) text tessellation is actually more important (and that's more than 2x faster!).
Sadly, the actual text cache lookup is significantly slower (300ns -> 600ns). That's because the `TextLayoutJob` is a lot bigger (it has more options, like underlining, fonts etc), so it is slower to hash and compare. I have an idea how to speed this up, but I need to do some other work before I can implement that.
All in all, the performance impact on `demo_with_tesselate__realistic` is about 5-6% in the red. Not great; not terrible. The benefits are worth it, but I also think with some work I can get that down significantly, hopefully down to the old levels.
2021-09-03 16:18:00 +00:00
|
|
|
|
2022-01-24 13:32:36 +00:00
|
|
|
let job = LayoutJob::simple(
|
|
|
|
LOREM_IPSUM_LONG.to_owned(),
|
|
|
|
font_id.clone(),
|
|
|
|
color,
|
|
|
|
wrap_width,
|
|
|
|
);
|
|
|
|
layout(&mut locked_fonts.fonts, job.into())
|
2022-03-21 20:48:35 +00:00
|
|
|
});
|
2022-01-24 13:32:36 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
c.bench_function("text_layout_cached", |b| {
|
|
|
|
b.iter(|| {
|
|
|
|
fonts.layout(
|
New text layout (#682)
This PR introduces a completely rewritten text layout engine which is simpler and more powerful. It allows mixing different text styles (heading, body, etc) and formats (color, underlining, strikethrough, …) in the same layout pass, and baked into the same `Galley`.
This opens up the door to having a syntax-highlighed code editor, or a WYSIWYG markdown editor.
One major change is the color is now baked in at layout time. However, many widgets changes text color on hovered. But we need to do the text layout before we know if it is hovered. Therefor the painter has an option to override the text color of a galley.
## Performance
Text layout alone is about 20% slower, but a lot of that is because more tessellation is done upfront. Text tessellation is now a lot faster, but text layout + tessellation still lands at a net loss of 5-10% in performance. There are however a few tricks to speed it up (like using `smallvec`) which I am saving for later. Text layout is also cached, meaning that in most cases (when all text isn't changing each frame) text tessellation is actually more important (and that's more than 2x faster!).
Sadly, the actual text cache lookup is significantly slower (300ns -> 600ns). That's because the `TextLayoutJob` is a lot bigger (it has more options, like underlining, fonts etc), so it is slower to hash and compare. I have an idea how to speed this up, but I need to do some other work before I can implement that.
All in all, the performance impact on `demo_with_tesselate__realistic` is about 5-6% in the red. Not great; not terrible. The benefits are worth it, but I also think with some work I can get that down significantly, hopefully down to the old levels.
2021-09-03 16:18:00 +00:00
|
|
|
LOREM_IPSUM_LONG.to_owned(),
|
2022-01-24 13:32:36 +00:00
|
|
|
font_id.clone(),
|
New text layout (#682)
This PR introduces a completely rewritten text layout engine which is simpler and more powerful. It allows mixing different text styles (heading, body, etc) and formats (color, underlining, strikethrough, …) in the same layout pass, and baked into the same `Galley`.
This opens up the door to having a syntax-highlighed code editor, or a WYSIWYG markdown editor.
One major change is the color is now baked in at layout time. However, many widgets changes text color on hovered. But we need to do the text layout before we know if it is hovered. Therefor the painter has an option to override the text color of a galley.
## Performance
Text layout alone is about 20% slower, but a lot of that is because more tessellation is done upfront. Text tessellation is now a lot faster, but text layout + tessellation still lands at a net loss of 5-10% in performance. There are however a few tricks to speed it up (like using `smallvec`) which I am saving for later. Text layout is also cached, meaning that in most cases (when all text isn't changing each frame) text tessellation is actually more important (and that's more than 2x faster!).
Sadly, the actual text cache lookup is significantly slower (300ns -> 600ns). That's because the `TextLayoutJob` is a lot bigger (it has more options, like underlining, fonts etc), so it is slower to hash and compare. I have an idea how to speed this up, but I need to do some other work before I can implement that.
All in all, the performance impact on `demo_with_tesselate__realistic` is about 5-6% in the red. Not great; not terrible. The benefits are worth it, but I also think with some work I can get that down significantly, hopefully down to the old levels.
2021-09-03 16:18:00 +00:00
|
|
|
color,
|
|
|
|
wrap_width,
|
2022-01-24 13:32:36 +00:00
|
|
|
)
|
2022-03-21 20:48:35 +00:00
|
|
|
});
|
2021-02-08 21:53:31 +00:00
|
|
|
});
|
|
|
|
|
2022-01-24 13:32:36 +00:00
|
|
|
let galley = fonts.layout(LOREM_IPSUM_LONG.to_owned(), font_id, color, wrap_width);
|
2022-04-03 16:14:27 +00:00
|
|
|
let font_image_size = fonts.font_image_size();
|
2022-05-10 17:31:19 +00:00
|
|
|
let prepared_discs = fonts.texture_atlas().lock().prepared_discs();
|
|
|
|
let mut tessellator = egui::epaint::Tessellator::new(
|
|
|
|
1.0,
|
|
|
|
Default::default(),
|
|
|
|
font_image_size,
|
|
|
|
prepared_discs,
|
|
|
|
);
|
2021-02-14 09:53:39 +00:00
|
|
|
let mut mesh = egui::epaint::Mesh::default();
|
2021-09-05 07:06:53 +00:00
|
|
|
let text_shape = TextShape::new(egui::Pos2::ZERO, galley);
|
2021-04-01 19:42:45 +00:00
|
|
|
c.bench_function("tessellate_text", |b| {
|
2021-02-08 21:53:31 +00:00
|
|
|
b.iter(|| {
|
2022-04-03 16:14:27 +00:00
|
|
|
tessellator.tessellate_text(&text_shape, &mut mesh);
|
2021-02-08 21:53:31 +00:00
|
|
|
mesh.clear();
|
2022-03-21 20:48:35 +00:00
|
|
|
});
|
2021-02-08 21:53:31 +00:00
|
|
|
});
|
|
|
|
}
|
2020-05-20 19:20:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
criterion_group!(benches, criterion_benchmark);
|
|
|
|
criterion_main!(benches);
|