Bug: PIL-based block height estimation causes severe performance degradation #38

Closed
opened 2026-03-19 05:32:36 +00:00 by david · 0 comments
Owner

Bug: PIL-based block height estimation causes severe performance degradation

State: open | Author: david
Created: 2026-03-19

Problem

The ViewportFilterStage in engine/pipeline/adapters/transform.py was using estimate_block_height() which uses PIL to render blocks and measure their height. This is extremely slow and causes:

  1. Severe performance degradation in viewport filtering
  2. Benchmark tests to fail with coverage instrumentation
  3. Unnecessary CPU overhead for simple height estimation

Root Cause

estimate_block_height() from engine/render/blocks.py renders each headline as a full PIL image to measure its terminal height - this is expensive and unnecessary.

Solution

Replace with simple word-wrap based estimation that:

  • Counts words and wraps at viewport width
  • Estimates 6 rows per wrapped line (big block rendering)
  • Is orders of magnitude faster

Fix Applied

See commit that replaces estimate_block_height with estimate_simple_height.

  • Part of #34 (Improve benchmarking system)
  • Related to #36 (CI benchmarking interference)

This bug is now fixed.

## Bug: PIL-based block height estimation causes severe performance degradation **State:** open | **Author:** david **Created:** 2026-03-19 ## Problem The `ViewportFilterStage` in `engine/pipeline/adapters/transform.py` was using `estimate_block_height()` which uses PIL to render blocks and measure their height. This is extremely slow and causes: 1. Severe performance degradation in viewport filtering 2. Benchmark tests to fail with coverage instrumentation 3. Unnecessary CPU overhead for simple height estimation ## Root Cause `estimate_block_height()` from `engine/render/blocks.py` renders each headline as a full PIL image to measure its terminal height - this is expensive and unnecessary. ## Solution Replace with simple word-wrap based estimation that: - Counts words and wraps at viewport width - Estimates 6 rows per wrapped line (big block rendering) - Is orders of magnitude faster ## Fix Applied See commit that replaces `estimate_block_height` with `estimate_simple_height`. ## Related Issues - Part of #34 (Improve benchmarking system) - Related to #36 (CI benchmarking interference) --- **This bug is now fixed.**
david closed this issue 2026-03-19 05:34:10 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: klubhaus/sideline#38