Skip to content

browser: Reduce spurious rendering and lock contention#56

Open
Yabuku-xD wants to merge 1 commit into
Glass-HQ:mainfrom
Yabuku-xD:perf/browser-rendering-optimizations
Open

browser: Reduce spurious rendering and lock contention#56
Yabuku-xD wants to merge 1 commit into
Glass-HQ:mainfrom
Yabuku-xD:perf/browser-rendering-optimizations

Conversation

@Yabuku-xD
Copy link
Copy Markdown

Summary

Four targeted, low-risk improvements to the browser crate's rendering pipeline — no new dependencies, no behavior changes, purely less wasted work:

  • Gate FrameReady on suspension (tab.rs): Skip emitting TabEvent::FrameReady for suspended tabs, matching the existing is_suspended guard on all other events.
  • Gate FrameReady notify on surface visibility (browser_view.rs): Only call cx.notify() from FrameReady when surface_state == Visible. In-flight frames queued just before a mode switch no longer trigger layout work on the hidden browser view.
  • Split RenderState Mutex (render_handler.rs, tab.rs, client.rs, life_span_handler.rs): Extract current_frame: Option<CVPixelBuffer> into its own Arc<Mutex<...>>. CEF's view_rect/screen_info geometry callbacks no longer share a lock with the 60fps on_accelerated_paint write path. Geometry queries and frame buffer writes now operate on independent locks — no contention between them.
  • Compute pinned_count once per render (tab_strip.rs, browser_view.rs): Both render_tab_strip and render_sidebar previously performed independent O(n) scans over all tabs to count pinned ones. A pinned_tab_count() helper is now called once in render() and passed as a parameter to both methods.

Test plan

  • cargo check -p browser passes with no errors
  • cargo check -p workspace -p browser passes
  • Mode switching (browser → editor → terminal → browser) remains smooth with no stale frames
  • Tab suspension/resume works correctly with no blank-frame artifacts

Release Notes:

  • N/A

@Yabuku-xD Yabuku-xD requested a review from naaiyy as a code owner April 21, 2026 23:32
@github-actions github-actions Bot added the first contribution Opened by a first-time contributor label Apr 21, 2026
@Yabuku-xD Yabuku-xD force-pushed the perf/browser-rendering-optimizations branch from f222f99 to 74ef763 Compare April 22, 2026 00:38
Four targeted improvements to the browser crate's rendering pipeline:

1. Gate FrameReady on suspension state (tab.rs): Skip emitting
   TabEvent::FrameReady for suspended tabs. CEF already stops rendering
   hidden browsers, but this prevents any in-flight frames from
   propagating cx.notify() after suspension.

2. Gate FrameReady cx.notify() on surface visibility (browser_view.rs):
   Only trigger a re-render when BrowserSurfaceState is Visible. In-flight
   FrameReady events queued just before a mode switch no longer cause
   spurious layout work on the hidden browser view.

3. Split RenderState Mutex (render_handler.rs, tab.rs, client.rs,
   life_span_handler.rs): Extract current_frame into its own
   Arc<Mutex<Option<CVPixelBuffer>>> separate from the geometry fields
   (width, height, scale_factor). CEF's view_rect and screen_info
   callbacks no longer share a lock with the 60fps frame write path,
   eliminating cross-contention between geometry queries and frame writes.

4. Compute pinned_count once per render pass (tab_strip.rs,
   browser_view.rs): Both render_tab_strip and render_sidebar previously
   ran an independent O(n) tab scan to count pinned tabs. The count is
   now computed once in the render() method via a pinned_tab_count()
   helper and passed as a parameter to both render methods.
@Yabuku-xD Yabuku-xD force-pushed the perf/browser-rendering-optimizations branch from 74ef763 to e32496a Compare April 22, 2026 00:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

first contribution Opened by a first-time contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants