Repository navigation
fix(preview): eliminate main-thread freeze when viewing large spreadsheets - #1946
Conversation
Fixes and benchmark resultsFixed secondary-column tie breaking, bounded lazy caches for ragged tables, redundant sorting/model replacement on rebuilds, and the failing ragged-selection regression. Sorting and copying now share the Rust row permutation. The original PR's GTK-comparator removal is retained. Benchmark source and benchmark documentation have been removed from the PR as requested; results belong here, not in the repository. MeasurementsAMD Ryzen 7 3750H, Rust 1.98.1, GTK 4.22.4, unoptimized test profile, private Xvfb/D-Bus. Dense fixtures used one warmup and five measured samples; numbers are medians. Widgets were unmapped: these measure model/widget work, not XLSX parsing, rendering, or Wayland responsiveness.
The measured candidate still regressed dense cold/warm sorting; a direct dense single-column fast path was added afterward. That final fast path has not been re-benchmarked, following the request to stop local runs. These measurements do not establish that final cold-sort latency improved. RSS is approximate and affected by allocator reuse; desktop load also affected timings. Validation already completed
Per explicit owner direction, no further local tests, benchmarks, or lint checks are being run; GitHub CI will validate the pushed revision. Local pinned fmt/clippy phases and full suites were not run. No screenshots or benchmark logs are committed. |
Dense-table CPU follow-up —
|
| Operation | Original PR CPU | Previous head CPU | New CPU | Previous → new elapsed |
|---|---|---|---|---|
| Model creation | 45.22 ms | 42.05 ms | 3.66 ms | 42.85 → 3.72 ms |
| Cold grouped-text sort | 17.64 ms | 15.66 ms | 4.11 ms | 16.00 → 4.19 ms |
| Warm sort-direction change | 13.90 ms | 12.01 ms | 0.72 ms | 12.27 → 0.72 ms |
| Copy displayed TSV | 12.03 ms | 5.54 ms | 3.40 ms | 5.74 → 3.46 ms |
| Cached-column switch after materializing every row object | 12.18 ms | 11.23 ms | 2.11 ms | 11.63 → 2.15 ms |
| Direction change after materializing every row object | 13.21 ms | 11.92 ms | 0.70 ms | 12.30 → 0.71 ms |
The three requested operations use approximately 91%, 74%, and 94% less CPU than the previous head in this optimized-model comparison.
Unoptimized model code (opt-level=0, debug assertions; nine measured samples after warmup) also improves those operations:
| Operation | Original PR CPU | Previous head CPU | New CPU | Previous → new elapsed |
|---|---|---|---|---|
| Model creation | 115.96 ms | 133.64 ms | 43.50 ms | 135.90 → 44.04 ms |
| Cold grouped-text sort | 40.39 ms | 46.72 ms | 25.38 ms | 52.11 → 26.64 ms |
| Warm sort-direction change | 29.15 ms | 35.26 ms | 1.76 ms | 38.24 → 1.78 ms |
These are fresh model-only comparisons, not directly interchangeable with the earlier unmapped-widget benchmark table.
RAM and tradeoffs
- On the ragged 25,000-row / 256-column fixture, retained RSS growth during column visits remains small: approximately 154 → 172 KiB between previous and new head, versus 150,132 KiB in the original PR. These are approximate medians across six fresh processes, affected by allocator reuse. Model items removed remain 24,999, versus 6,399,744 in the original PR.
- Ragged optimized CPU is essentially unchanged versus the previous head: 151.20 → 151.64 ms; it is not a demonstrated further speedup there.
- Lazy allocation shifts some cost to first item access: requesting the first 100 row objects takes 0.038 → 0.142 ms CPU. A separate fresh-model benchmark that creates and immediately materializes all rows takes 42.51 → 31.76 ms CPU optimized, and 125.66 → 118.80 ms unoptimized. The original PR's unoptimized full-materialization result was 112.48 ms, so that deliberately eager workload is still slightly slower than the original PR. This is not a claim that every operation became faster.
Verification and owner-directed scope
The pinned manual build completed. Through ./scripts/qa-drive.sh, repeated header reversals preserved secondary/casefold ties, and a real 100,000-cell CSV rendered, scrolled to newly materialized rows with matching source values, and reversed back correctly, with no GTK warnings/criticals. This was a manual observation, not a qa.sh scenario run. Initial manual probes targeting the header or offscreen buffer rows were corrected to body/visible targets.
Extended the existing sort/cache regressions and QA scenario, and added row-object identity/lifetime coverage, including headerless tables, clearing sorting, out-of-range model access, and model survival after TableState drops.
Per explicit owner direction, no local CI suites, Rust regression suite, qa.sh suite, or pinned fmt/clippy phases were run. Only benchmark builds/runs, native source formatting, and the pinned manual UI build/drive were performed locally. git diff --check passed. Benchmark sources and CSVs remain outside the repository.
The local measurement commands (all successful, non-empty selections) were:
python3 /tmp/strata-pr1946-cpu-XisW4M/build.py optimized
python3 /tmp/strata-pr1946-cpu-XisW4M/run.py optimized final original before candidate
BENCH_FIXTURES=25000,ragged,eager python3 /tmp/strata-pr1946-cpu-XisW4M/run.py optimized confirm candidate before original
python3 /tmp/strata-pr1946-cpu-XisW4M/build.py debug
python3 /tmp/strata-pr1946-cpu-XisW4M/run.py debug final original before candidate
BENCH_FIXTURES=eager python3 /tmp/strata-pr1946-cpu-XisW4M/run.py debug confirm candidate before originalEach profile was rebuilt before its runs. Dense runs selected nine measured iterations plus a warmup per fixture/revision; ragged runs selected three fresh processes per revision per round. The manual check used STRATA_CONTAINER_ENGINE=podman ./scripts/qa-drive.sh start with the five-row CSV fixture and isolated preferences, followed by individual send commands and stop. The first launch's unsupported array-shaped fixture was rejected; the supported fixture launched successfully, and the large CSV was generated inside its private fixture directory.
GitHub CI for 01dca680: all build/lint, four Rust shards, aggregate coverage, script and policy checks passed (run). The automated QA job was skipped by the workflow's default PR policy, not passed; only the pinned manual UI observations above cover that path locally.
ReviewNo blocking bugs found. One minor behavior inconsistency and two small test notes below. 1. Rebuilt tables drop secondary sort columns from the header but keep them in the rows (low severity, document tables only)
When it happens: only tables embedded in document previews. Those widgets are rebuilt when the virtual list rebinds the row, for example when the table scrolls out of view and back ( Repro: in a document table, click "group", then "name". Scroll the table away and back, then click "name" again. Rows with equal names fall back to source order instead of staying grouped. The old code also lost the secondary sort on rebuild ( 2. An existing test lost a check (
|
|
lgtm, just needs verified signatures on commits |
Like-for-like widget benchmark: remaining sort regressions and RAMCorrection to the interpretation of my earlier model-only results: those results did not establish faster GTK header actions. The fresh full-widget benchmark below finds that cold and warm header sorting still regress against the original PR. Startup, redundant actions, rebuilds, copying and sparse-cache RAM improve, but this is not an across-the-board performance win. Both the original PR ( Environment: AMD Ryzen 7 3750H, GTK 4.22.4 / GLib 2.88.3, native Cargo test profile unoptimized + debuginfo, private Xvfb/private D-Bus, accessibility bridge disabled. Checking the compiler inside the native runner's isolated environment reports Rust/Cargo 1.97.1, rather than the parent shell's 1.98.1. The two revisions use that same compiler. The previous standalone model-only measurements did use Rust 1.98.1. These are unmapped widgets, not XLSX parsing, drawing, or visible-window responsiveness measurements. Dense measurements: one warmup plus five measured samples in each of three fresh processes per revision/fixture, with revision order alternated between rounds; medians of 15 samples. Ragged measurements: three fresh processes per revision. Historical measurements are not reused in the fresh comparison. The complete original table, freshly remeasured
The latest code honors secondary-column tie-breaking that the original PR omitted. That correctness difference does not erase the measured latency regressions. I have not yet profiled their cause in the GTK header-action path. Actual CPU time, not CPU percentageProcess user+system CPU time; main GTK-thread CPU was recorded independently and closely matched:
So the full-widget cold/warm actions use approximately 12% and 101% more CPU than the original PR in this unoptimized experiment. The earlier 74%/94% CPU reductions applied only to isolated model operations against previous head RAM: growth is not total usageThe old “784 KiB” figure was additional RSS during column visits, not total application RAM. The fresh 700 KiB figure has that same meaning. Approximate total RSS of the benchmark process, including GTK, code/resources, fixtures, widgets and allocator retention:
Dense retained process RSS is essentially unchanged in this experiment. The demonstrated large RAM improvement is in the ragged case: approximately 149 MiB of extra sort-cache growth avoided. RSS is approximate and allocator-dependent; these totals do not establish total RAM of a normal visible Strata session. What the lazy-row tradeoff actually isRow-object construction is deferred to first access rather than paid for every row up front. Objects are cached, not evicted as rows scroll away, so visiting every row can eventually materialize the whole table. The separate force-all-items, unoptimized model stress test was slightly slower than the original PR (118.80 versus 112.48 ms CPU), although faster than the previous branch head. This is distinct from the unresolved header-sort regressions above. Local scope and repository state./scripts/test-headless.py --config build.jobs=2 --no-run ui::table_view::widget_benchmark::compare_original_and_latest
./scripts/test-headless.py --config build.jobs=2 ui::table_view::widget_benchmark::compare_original_and_latest -- --ignored --exact --nocapture --test-threads=1The temporary original-module build initially needed missing namespace aliases corrected; the corrected build completed. The exact benchmark selection passed: one outer benchmark, all 18 fixture/revision subprocess runs, with all expected nonzero sample counts. No Rust regression suite, QA scenario suite, or local CI/lint phases ran. The temporary module declaration was removed, |
01dca68 to
d2b4ed0
Compare
Verified signatures: merge blocker clearedWith explicit owner consent, replaced the five unsigned PR commits with the single GitHub-signed Verified commit
The owner explicitly authorized the history rewrite and directed CI to GitHub. No local builds, test suites or lint phases were run for this signature-only update. Previous benchmark findings, including the remaining GTK header-sort regressions, are unchanged. The temporary signing branch was deleted; the previous head remains preserved in local ref |
Description
Resolves #1939.
Single-clicking a spreadsheet file with large numbers of rows (e.g. 15,000–25,000 rows, up to 100,000 cells) previously froze the GTK main loop for ~5 seconds before displaying the preview.
Root Cause
TableStatepreviously wrapped agio::ListStorewith agtk::SortListModeland agtk::CustomSorter. For 20,000 rows, sorting on the main loop performed ~300,000 comparisons across the C-FFI boundary, with two GObject dynamic type checks (g_type_check_instance_is_a) and twoRefCellborrows per comparison.SortKeygeneration was executed eagerly across all columns during creation, allocating lowercase strings for text cells in every column even when never sorted.splice, forcing GTK to tear down and rebuild list structures twice.Fix
gtk::SortListModelwith pure in-memory Rust slice sorting (indices.sort_by) ongio::ListStore. Sorting 25,000 rows dropped from ~4,500ms to <10ms.column_sort_keys: Vec<RefCell<Option<Vec<SortKey>>>>). Untouched columns never parse or allocate lowercase text.spliceand re-layout pass.Performance Verification
Tested in isolated Arch Linux KDE Plasma / Wayland VM:
freeze_5s.xlsx(18,000 rows × 4 cols = 72,000 cells):cells_100k.xlsx(25,000 rows × 4 cols = 100,000 cells):Visual Evidence
spreadsheet_preview_navigation.mp4
cells_100k_preview_verified.mp4
freeze_5s_preview.mp4
Follow-up: lazy table rows and CPU measurement
The follow-up uses a table-local lazy row model, reuses primary-key groups on sort-direction changes, and precomputes column populations. Row identities and the displayed/copy/selection order remain shared. Fresh CPU, elapsed-time and RAM measurements, including limitations and tradeoffs, are recorded in the follow-up comment rather than committed benchmark files.
Manual check: preview a CSV with repeated values, click another column header twice, switch the primary header, then scroll a large table. Equal keys should retain their secondary ordering, and newly visible rows should show the matching cells.
Per explicit owner direction, CI suites and pinned lint phases are left to GitHub, not run locally; local work was limited to performance builds/measurements, source formatting and a pinned isolated manual UI build/drive.
Verified signature history
With explicit owner approval, the five unsigned PR commits were consolidated into GitHub-verified commit
d2b4ed0fand the same PR branch was updated with an exact-head--force-with-leaseguard. Its complete Git tree is identical to01dca680, so the code, prior benchmark findings and known header-sort regressions are unchanged. No signing keys or branch protections were changed.This is a signature/history-only update. Per owner direction, CI runs on GitHub; no local builds, test suites or lint phases were run for it.