Skip to content

Optimize staggered grid layout to minimize whitespace gaps#1

Open
techeretic wants to merge 1 commit into
mainfrom
feature/optimize-grid-gap-minimization
Open

Optimize staggered grid layout to minimize whitespace gaps#1
techeretic wants to merge 1 commit into
mainfrom
feature/optimize-grid-gap-minimization

Conversation

@techeretic

Copy link
Copy Markdown
Owner

Summary

  • Add SegmentOptimizer — a new utility that reorders items within each segment (groups of single-span items between full-span items) to minimize column height imbalance in the 2-column LazyVerticalStaggeredGrid
  • Simulation-based hill climbing algorithm — simulates the grid's "shortest column first" placement, scores orderings by cumulative column height difference, and iteratively swaps items to find the optimal arrangement. Starts from an LPT (Longest Processing Time) initial solution for fast convergence
  • Reduce grid spacing from 8dp to 4dp (content padding, horizontal arrangement, and vertical item spacing) for a tighter, denser layout

How it works

  1. Full-span items reset both columns to equal height, creating natural "segments" of single-span items
  2. For each segment (~5-15 items), the optimizer simulates how the grid places items and finds the ordering that keeps both columns as balanced as possible
  3. The optimization runs once on the full dataset at initialization, so paginated pages serve already-optimized slices with zero runtime overhead

Files changed

File Change
SegmentOptimizer.kt New — segment extraction, gap scoring simulation, hill climbing optimizer
GridItemRepository.kt Wrap dataset with SegmentOptimizer.optimize()
StaggeredGridScreen.kt Reduce grid spacing from 8dp to 4dp

Test plan

  • Verify app builds and installs without errors
  • Scroll through the grid and confirm columns are visually balanced with minimal whitespace
  • Verify full-span items still appear correctly with 5+ single items between them
  • Verify pagination and loading indicators work as before
  • Test both Fast and Slow network speeds

🤖 Generated with Claude Code

Add SegmentOptimizer that reorders items for optimal column balancing
using simulation-based hill climbing on the grid's "shortest column
first" placement algorithm. Also tighten grid spacing from 8dp to 4dp.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant