Ensure render loop operations stay within frame time budget (typically 16.67ms for 60fps). Avoid expensive computations, traversals, and I/O operations during frame rendering. Instead, compute and cache results ahead of time or move heavy operations to background tasks.
Ensure render loop operations stay within frame time budget (typically 16.67ms for 60fps). Avoid expensive computations, traversals, and I/O operations during frame rendering. Instead, compute and cache results ahead of time or move heavy operations to background tasks.
Example of problematic code:
fn render_outline(&self, cx: &mut Context) {
// Bad: Expensive loop during rendering
for outline in self.outlines {
if self.has_outline_children(outline, cx) {
// ... rendering logic
}
}
}
Better approach:
fn render_outline(&self, cx: &mut Context) {
// Good: Use pre-computed results during render
for (outline, has_children) in &self.cached_outline_data {
if *has_children {
// ... rendering logic
}
}
}
// Update cache in background or on data changes
fn update_outline_cache(&mut self, cx: &mut Context) {
let mut cached_data = Vec::new();
for outline in self.outlines {
cached_data.push((outline, self.has_outline_children(outline, cx)));
}
self.cached_outline_data = cached_data;
}
Key guidelines:
Enter the URL of a public GitHub repository