-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[APP-5825] Bypass layout cache for editor text #15831
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e17906b
APP-5825 Add parallel editor layout benchmark
warp-agent-staging[bot] 341ccfe
APP-5825 Bypass layout cache for editor text
warp-agent-staging[bot] 43d762a
APP-5825 Cover text-frame fallback requests
warp-agent-staging[bot] a67c645
APP-5825 benchmark native CoreText layout
warp-agent-staging[bot] bfc5b97
APP-5825 benchmark unique native layout blocks
warp-agent-staging[bot] 89349a1
APP-5825 preserve Criterion benchmark config
warp-agent-staging[bot] b5a7609
fix(editor): refine uncached layout benchmark
warp-agent-staging[bot] 3af13a5
refactor(warpui): remove unused uncached line layout
warp-agent-staging[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| use std::hint::black_box; | ||
| use std::sync::Arc; | ||
| use std::time::Duration; | ||
|
|
||
| use criterion::{Criterion, Throughput, criterion_group, criterion_main}; | ||
| use rayon::ThreadPoolBuilder; | ||
| use string_offset::CharOffset; | ||
| use warp_editor::content::buffer::{StyledBufferBlock, StyledBufferRun, StyledTextBlock}; | ||
| use warp_editor::content::edit::EditDelta; | ||
| use warp_editor::content::text::{BufferBlockStyle, TextStylesWithMetadata}; | ||
| use warp_editor::render::layout::TextLayout; | ||
| use warp_editor::render::model::{ | ||
| BrokenLinkStyle, CheckBoxStyle, HorizontalRuleStyle, InlineCodeStyle, ParagraphStyles, | ||
| RenderLayoutOptions, RichTextStyles, TableStyle, | ||
| }; | ||
| #[cfg(target_os = "macos")] | ||
| use warpui::platform::mac::FontDB as MacFontDB; | ||
| use warpui_core::App; | ||
| use warpui_core::color::ColorU; | ||
| use warpui_core::elements::{Border, Fill}; | ||
| #[cfg(target_os = "macos")] | ||
| use warpui_core::fonts::Cache as FontCache; | ||
| use warpui_core::fonts::{FamilyId, Weight}; | ||
| use warpui_core::units::IntoPixels; | ||
|
|
||
| const BLOCK_COUNT: usize = 4_096; | ||
| const RAYON_THREAD_COUNT: usize = 6; | ||
| const SHAPING_TEXT: &str = concat!( | ||
| "office affinity efficient waffle: ffi ffl fi fl; ", | ||
| "English left-to-right text surrounds العربية: السَّلَامُ عَلَيْكُمْ ورحمة الله, ", | ||
| "then עברית: שלום עולם and mixed account-42 مرحبا status=ready; ", | ||
| "combining marks: café naïve coöperate Ångström; ", | ||
| "Devanagari: नमस्ते दुनिया; Thai: สวัสดีชาวโลก; ", | ||
| "emoji and joiners: 👩💻 👨👩👧👦; " | ||
| ); | ||
|
|
||
| fn benchmark_block(text: String) -> StyledBufferBlock { | ||
| let content_length = text.chars().count(); | ||
| StyledBufferBlock::Text(StyledTextBlock { | ||
| block: vec![StyledBufferRun { | ||
| run: text, | ||
| text_styles: TextStylesWithMetadata::default(), | ||
| block_style: BufferBlockStyle::PlainText, | ||
| }], | ||
| style: BufferBlockStyle::PlainText, | ||
| content_length: CharOffset::from(content_length), | ||
| }) | ||
| } | ||
|
|
||
| fn benchmark_styles(font_family: FamilyId) -> RichTextStyles { | ||
| let white = ColorU::white(); | ||
| let paragraph = ParagraphStyles { | ||
| font_family, | ||
| font_size: 13., | ||
| font_weight: Weight::Normal, | ||
| line_height_ratio: 1.2, | ||
| text_color: white, | ||
| baseline_ratio: 0.8, | ||
| fixed_width_tab_size: None, | ||
| }; | ||
| RichTextStyles { | ||
| base_text: paragraph, | ||
| code_text: ParagraphStyles { | ||
| fixed_width_tab_size: Some(4), | ||
| ..paragraph | ||
| }, | ||
| code_background: Fill::None, | ||
| embedding_background: Fill::None, | ||
| embedding_text: paragraph, | ||
| code_border: Border::new(0.), | ||
| placeholder_color: white, | ||
| selection_fill: Fill::None, | ||
| cursor_fill: Fill::None, | ||
| inline_code_style: InlineCodeStyle { | ||
| font_family, | ||
| background: white, | ||
| font_color: white, | ||
| }, | ||
| check_box_style: CheckBoxStyle { | ||
| border_width: 2., | ||
| border_color: white, | ||
| icon_path: "bundled/svg/check-thick.svg", | ||
| background: white, | ||
| hover_background: white, | ||
| }, | ||
| horizontal_rule_style: HorizontalRuleStyle { | ||
| rule_height: 2., | ||
| color: white, | ||
| }, | ||
| broken_link_style: BrokenLinkStyle { | ||
| icon_path: "bundled/svg/link-broken-02.svg", | ||
| icon_color: white, | ||
| }, | ||
| block_spacings: Default::default(), | ||
| minimum_paragraph_height: Some(24.0.into_pixels()), | ||
| show_placeholder_text_on_empty_block: false, | ||
| cursor_width: 1., | ||
| highlight_urls: false, | ||
| table_style: TableStyle { | ||
| border_color: white, | ||
| header_background: white, | ||
| cell_background: white, | ||
| alternate_row_background: None, | ||
| text_color: white, | ||
| header_text_color: white, | ||
| scrollbar_nonactive_thumb_color: white, | ||
| scrollbar_active_thumb_color: white, | ||
| font_family, | ||
| font_size: 13., | ||
| cell_padding: 8., | ||
| outer_border: true, | ||
| column_dividers: true, | ||
| row_dividers: true, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| fn benchmark_delta(texts: impl IntoIterator<Item = String>) -> (EditDelta, usize) { | ||
| let blocks: Vec<_> = texts.into_iter().map(benchmark_block).collect(); | ||
| let chars = blocks | ||
| .iter() | ||
| .map(StyledBufferBlock::content_length) | ||
| .map(CharOffset::as_usize) | ||
| .sum(); | ||
| ( | ||
| EditDelta { | ||
| old_offset: CharOffset::from(1)..CharOffset::from(1 + chars), | ||
| new_lines: Arc::new(blocks), | ||
| ..Default::default() | ||
| }, | ||
| chars, | ||
| ) | ||
| } | ||
|
|
||
| fn layout_delta( | ||
| delta: &EditDelta, | ||
| text_layout: &TextLayout<'_>, | ||
| layout_options: &RenderLayoutOptions, | ||
| app: &warpui_core::AppContext, | ||
| ) { | ||
| black_box(delta.layout_delta(text_layout, None, layout_options, None, app)); | ||
| } | ||
|
|
||
| fn text_layout_benchmarks(criterion: &mut Criterion) { | ||
| ThreadPoolBuilder::new() | ||
| .num_threads(RAYON_THREAD_COUNT) | ||
| .build_global() | ||
| .expect("benchmark should initialize Rayon before first use"); | ||
| let (test_delta, test_chars) = benchmark_delta( | ||
| (0..BLOCK_COUNT).map(|index| format!("{SHAPING_TEXT} test-backend-block-{index:04}\n")), | ||
| ); | ||
| let test_styles = benchmark_styles(FamilyId(0)); | ||
| let layout_options = RenderLayoutOptions::default(); | ||
| #[cfg(target_os = "macos")] | ||
| let (core_text_font_cache, core_text_styles, core_text_delta, core_text_chars) = { | ||
| let mut font_cache = FontCache::new(Box::new(MacFontDB::new())); | ||
| let font_family = font_cache | ||
| .load_system_font("Menlo") | ||
| .expect("Menlo should be available on macOS"); | ||
| let (delta, chars) = benchmark_delta( | ||
| (0..BLOCK_COUNT).map(|index| format!("{SHAPING_TEXT} core-text-block-{index:04}\n")), | ||
| ); | ||
| (font_cache, benchmark_styles(font_family), delta, chars) | ||
| }; | ||
| let mut criterion = std::mem::take(criterion); | ||
|
|
||
| App::test((), move |app| async move { | ||
| app.read(|ctx| { | ||
| let test_text_layout = TextLayout::new( | ||
| ctx.font_cache().text_layout_system(), | ||
| &test_styles, | ||
| f32::MAX, | ||
| ); | ||
| layout_delta(&test_delta, &test_text_layout, &layout_options, ctx); | ||
| #[cfg(target_os = "macos")] | ||
| { | ||
| let core_text_layout = TextLayout::new( | ||
| core_text_font_cache.text_layout_system(), | ||
| &core_text_styles, | ||
| f32::MAX, | ||
| ); | ||
| layout_delta(&core_text_delta, &core_text_layout, &layout_options, ctx); | ||
| } | ||
| { | ||
| let mut group = criterion.benchmark_group("editor_text_layout/test_backend"); | ||
| group.throughput(Throughput::Elements(test_chars as u64)); | ||
| group.bench_function("layout_delta_4096_shaping_blocks_6_threads", |bench| { | ||
| bench.iter(|| { | ||
| let text_layout = TextLayout::new( | ||
| ctx.font_cache().text_layout_system(), | ||
| &test_styles, | ||
| f32::MAX, | ||
| ); | ||
| layout_delta(&test_delta, &text_layout, &layout_options, ctx) | ||
| }) | ||
| }); | ||
| group.finish(); | ||
| } | ||
| #[cfg(target_os = "macos")] | ||
| { | ||
| let mut group = criterion.benchmark_group("editor_text_layout/core_text"); | ||
| group.throughput(Throughput::Elements(core_text_chars as u64)); | ||
| group.bench_function("layout_delta_4096_shaping_blocks_6_threads", |bench| { | ||
| bench.iter(|| { | ||
| let text_layout = TextLayout::new( | ||
| core_text_font_cache.text_layout_system(), | ||
| &core_text_styles, | ||
| f32::MAX, | ||
| ); | ||
| layout_delta(&core_text_delta, &text_layout, &layout_options, ctx) | ||
| }) | ||
| }); | ||
| group.finish(); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| criterion_group! { | ||
| name = benches; | ||
| config = Criterion::default() | ||
| .sample_size(20) | ||
| .warm_up_time(Duration::from_secs(2)) | ||
| .measurement_time(Duration::from_secs(5)); | ||
| targets = text_layout_benchmarks | ||
| } | ||
| criterion_main!(benches); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.