Replies: 5 comments 6 replies
-
I have seen @osiewicz improved this method in #22566. I have done a check to confirm this change is included on my test. |
Beta Was this translation helpful? Give feedback.
-
In the scene in my Table, the rows and columns are already virtual lists, and the actual rendered cells are only about From the current performance, the FPS drop caused by more than 400 text rendering is a bit strange, and I also noticed that the CPU overhead during scrolling (including ScrollWheel) is also worth paying attention to (often reaching more than 70% CPU, so I have only recently analyzed this issue. I have been comparing the performance differences between Zed and the Demo I wrote and our Application. It seems that because the Table and our actual Application UI have more elements than, the CPU usage will be higher than Zed (When there is operation: Zed is about 40%, mine is 70% - 100%), but the standby state is relatively normal. |
Beta Was this translation helpful? Give feedback.
-
I make an example for this case. |
Beta Was this translation helpful? Give feedback.
-
I have done a test. If add a period (10s) and then recycle cache, it can a little improve. However, this 10s is not reasonable. I am not sure whether many characters will be rendered in 10s, resulting in excessive memory usage. diff --git a/crates/gpui/src/text_system/line_layout.rs b/crates/gpui/src/text_system/line_layout.rs
index 360042d98e..c467b86480 100644
--- a/crates/gpui/src/text_system/line_layout.rs
+++ b/crates/gpui/src/text_system/line_layout.rs
@@ -7,6 +7,7 @@ use std::{
hash::{Hash, Hasher},
ops::Range,
sync::Arc,
+ time::{Duration, Instant},
};
use super::LineWrapper;
@@ -397,6 +398,7 @@ pub(crate) struct LineLayoutCache {
#[derive(Default)]
struct FrameCache {
+ last_clean: Option<Instant>,
lines: FxHashMap<Arc<CacheKey>, Arc<LineLayout>>,
wrapped_lines: FxHashMap<Arc<CacheKey>, Arc<WrappedLineLayout>>,
used_lines: Vec<Arc<CacheKey>>,
@@ -459,8 +461,16 @@ impl LineLayoutCache {
let mut prev_frame = self.previous_frame.lock();
let mut curr_frame = self.current_frame.write();
std::mem::swap(&mut *prev_frame, &mut *curr_frame);
- curr_frame.lines.clear();
- curr_frame.wrapped_lines.clear();
+
+ // Keep frame cache 10 seconds.
+ // This for avoid text rendering performance issue when the text is changing frequently and reduce CPU usage.
+ if curr_frame.last_clean.map_or(true, |last| {
+ Instant::now().duration_since(last) > Duration::from_secs(10)
+ }) {
+ curr_frame.lines.clear();
+ curr_frame.wrapped_lines.clear();
+ curr_frame.last_clean = Some(Instant::now());
+ }
curr_frame.used_lines.clear();
curr_frame.used_wrapped_lines.clear();
}
|
Beta Was this translation helpful? Give feedback.
-
zed/crates/gpui/src/elements/div.rs Lines 1830 to 1835 in 69b9811 This part of code, in Table or List cases, may have an improvement space. If the TableRow and ListItem have hover style, this lines will always called This also exist in Zed How to test this side effect?Add a zed/crates/project_panel/src/project_panel.rs Lines 4318 to 4320 in 69b9811 And then mouse move on some other area outside the ProjectPanel that have hover style, for example the Panel Tab or the Button on StatusBar. Every mouse move will show a print. |
Beta Was this translation helpful? Give feedback.
-
layout_wrapped_line
not fast enough, if there have a lot of texts to render.Recently, I have going to find out the gpui-component table performance issues.
And then I found that:
CleanShot.2025-02-05.at.16.35.27.mp4
So, I used the samply to measure the performance.
git clone https://github.com/longbridge/gpui-component.git cd gpui-component cargo build --release --example table samply record ./target/release/examples/table
Then I found that maybe there problem caused by the text rendering.
Test Result
Case 1: By ScrollWheel
In this case, the
layout_wrapped_line
cost is5.8%
(Plus left about12%
)Case 2: By Drag
In this case is
34%
(Actually if plus left one all cost will be about50%
)I have read the source code of the
layout_wrapped_line
, there have a cache used previous frame.But in drag scrolling case, it may always cache miss, because drag range is
too large
, so it is so many texts are not same.zed/crates/gpui/src/text_system/line_layout.rs
Lines 492 to 519 in 8edcaec
Beta Was this translation helpful? Give feedback.
All reactions