Commit Graph
5 Commits
Author SHA1 Message Date
dailz 4421da35f4 perf(core): linear mmap VHI rebuild + zero-alloc wrap helpers
Four changes that compound to a 2-5x speedup on VHI rebuild for large
files, plus eliminating one full wasted VHI pass on initial open.

* spawn_indexer no longer computes VHI inline (progressive_reader.rs).
  The inline VHI used a hardcoded width=80, was invalidated immediately
  on Loading->Ready transition (gutter digit-boundary), and triggered
  a second full rebuild. Now returns visual_height_index: None and lets
  the UI trigger one rebuild with the correct post-layout width.

* spawn_visual_height_rebuild rewritten as a single linear pass over
  mmap bytes using memchr::memchr (SIMD) to find newlines, replacing
  the byte-by-byte BufRead::read_until scan. Cancel check throttled
  to every 1MB instead of per-line.

* wrap_line_count(&str, width) -> usize added as a zero-allocation
  counterpart to wrap_line_chars. Property tests cover ASCII, CJK,
  emoji, combining marks, tabs, zero-width chars, control chars, and
  real log lines across many widths - all match wrap_line_chars().len()
  exactly. compute_text_visual_height now uses wrap_line_count, removing
  10M Vec allocations on a 10M-line file.

* format_json_line returns Cow<'_, str> instead of String. Non-JSON
  lines borrow the input (zero allocation); only pretty-printed JSON
  objects allocate. Removes another 10M allocations when json_format=true.

Removes now-unused compute_visual_heights (only caller was the deleted
inline VHI path).
2026-06-22 14:52:01 +08:00
dailz 5cb56dafd8 fix(core): correct tab-stop alignment and width overflow in wrap_line_chars
- Extract TAB_WIDTH constant (4) replacing magic numbers
- Calculate tab stop as TAB_WIDTH - (col % TAB_WIDTH) for proper alignment
- Split tab expansion across rows when width < TAB_WIDTH
- Update test_wrap_with_tab expected value for new behavior
- Add tests: narrow width, stop alignment, line boundary, regression

Fixes: #27
2026-06-11 13:37:14 +08:00
dailz e99861c76d fix(tui): add MAX_WRAP_INPUT_LEN guard to prevent UI freeze on oversized lines (closes #26)
- compute_line_entry/compute_visual_height: double guard (raw + post-format)
- Skip detect_level on oversized raw input to avoid O(n) JSON parsing
- Add post-format guard for JSON lines that expand beyond 10MB
- progressive_reader: add post-format guard to compute_line_visual_height
- Add truncate_to_columns helper using existing wrap_line_chars
- Fix misleading docstring on MAX_WRAP_INPUT_LEN constant
- Add 6 regression tests covering all guard paths
2026-06-11 13:15:11 +08:00
dailz b58d66f2aa fix(io): use unicode-width for correct CJK/emoji/zero-width display width (closes #12) 2026-06-07 12:50:17 +08:00
dailzandSisyphus 210eecfa66 feat(core): extract wrap utilities and extend LineIndex for progressive loading
Move wrap_line_chars and format_json_line from app.rs to core/io/wrap.rs with MAX_WRAP_INPUT_LEN guard. Add serde derives, pub getters, and extend_from_bytes() to LineIndex for incremental index building.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-04-14 09:06:52 +08:00