Repository navigation
fs_grep: ripgrep tier 5+6 — byte walker + Boyer-Moore-Horspool - #241
Merged
Merged
Conversation
Two more cheap wins for fs_grep on top of the tier-1-4 filters (deferred-hash / blocked-dirs / NUL-sniff / size-cap), this time in the inner per-file path. Tier 5 -- walk bytes, not lines. The old ScanFile did: - StringReplace(Body, #13, '', [rfReplaceAll]) -- whole-body copy - Lines := TStringList.Create / Lines.Text := ... -- one alloc per line - LowerCase(Lines[j]) -- one per match-candidate None of that's needed. The new walker splits on #10 in place, trims trailing #13 inline for CRLF, and only Copy()s the line bytes on lines that actually matched. ~3-5x faster on the per-file path for typical source files. Tier 6 -- Boyer-Moore-Horspool substring search. The old Pos(PatLower, Cmp) advanced one byte at a time. BMH precomputes a 256-entry shift table once at Tool_FSGrep startup and on a failed alignment slides the pattern by up to m bytes instead of 1. For the patterns the model actually queries (TODO, function, class, FIXME, def, return) this hits ~3-10x fewer text-byte reads than Pos. Case-insensitive is handled by folding text bytes through a 256-entry ASCII lower table (built once per call) -- one branch instead of the old per-line LowerCase(). Pattern is pre-lowered into PatLower the same way as before. Output is byte-identical to the old path except: - CRLF lines no longer carry a stray #13 in the emitted line text (the old StringReplace pass had hidden this; the byte walker now trims trailing #13 explicitly). - Lone mid-line #13 bytes (extremely rare; old Mac line endings) are no longer stripped from output. ripgrep treats them the same way -- they're not a line terminator in modern conventions. Both behaviours are pinned by src/tests/fs_grep_tier5_6_tests.pas (10 cases): line numbers exact across the walker, CRLF trimming correct, files without trailing newline still produce a final-line match, one hashline header per matched file, ignore_case round-trip through the byte-fold table, BMH overlapping/partial/embedded patterns, m=1 degenerate case, m > n early exit, empty / newline- only bodies don't crash, and the hashline ¶path#hash header still emits in the same shape so fs_edit_hashline downstream still parses the output.
FMXExpress
force-pushed
the
claude/fs-grep-rg-tier5-6
branch
from
June 12, 2026 22:46
d592258 to
16e27e1
Compare
FMXExpress
pushed a commit
that referenced
this pull request
Jun 13, 2026
Both changelog files were stuck at the 2026-06-10 TUI / background- subagent / session_search / tool-RPC entries. ~7 weeks of merged PRs (#214 through #244) had landed without a corresponding entry in either file -- the git log was the only record of features like the knowledgebase, inbound MCP server mode, checkpoints + /undo, heartbeat daemon, shell backends (local | docker), send_message, promptware defense, Windows shell-output encoding fixes, fs_grep ripgrep optimisations, OpenTelemetry traces, and `pasclaw agent --quiet`. Added (newest first): 2026-06-13 #244 agent --quiet log-level clamp 2026-06-12 #243 dcc64 search path + agent --quiet / -q #242 OpenTelemetry traces (OTLP/HTTP+JSON) #241 fs_grep tier 5+6 (byte walker + Boyer-Moore-Horspool) #240 fs_grep tier 1-4 (deferred hash + skip-dirs + binary sniff + size cap) 2026-06-11 #239 Windows shell output: auto-detect UTF-8 vs OEM #238 Hashline fs_read header mojibake fix (¶ vs ¶) #237 Windows shell output: OEM codepage decode 2026-06-10 #233 Shell backends (local | docker via IShellBackend) #232 Heartbeat daemon + reversible condensation (CCR) #230 send_message tool + condenser families + promptware defense + task-aware MEMORY.md slicing 2026-06-09 #223 /goal Ralph loop + judge model + JSON-aware condenser #222 /undo wired into agent + sample dprojs #221 Checkpoints (auto-snapshot + TUI /undo) #220 mcp catalog: lenient hub projector #219 mcp: SSE / Streamable HTTP / stdio hub transports #218 Inbound MCP server mode #217 onboard: offer to index docs into the knowledgebase #214 Knowledgebase (RAG over operator-curated docs) Skipped from this changelog (build-system / Delphi-fix / FPC-fix PRs visible in the git log but not user-facing features): #215, #216, #224, #225, #226, #227, #228, #229, #231, #234, #236. Both files (README.md and docs/changelog.md) updated with the same entries -- intentional mirror so a reader on either surface sees the same history. Same prose in both; same footnote refs at the bottom. Validated: every [#N] reference in both files has a matching [#N]: URL footnote (no broken links).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two more ripgrep-inspired wins for
Tool_FSGrep, this time in the per-file scanner loop (independent from PR #240's walk-time filters):Tier 5 — walk bytes, not lines. The old
ScanFiledid:StringReplace(Body, #13, '', [rfReplaceAll])— whole-body copyTStringList.Text := ...— oneAnsiStringalloc per lineLowerCase(Lines[j])per match-candidate lineNone of which is necessary. The new walker splits on
#10in place, trims trailing#13inline for CRLF, and onlyCopy()s the line bytes on lines that actually matched. ~3-5× faster on the per-file path for typical source files.Tier 6 — Boyer-Moore-Horspool substring search.
Pos(PatLower, Cmp)advances one byte at a time. BMH precomputes a 256-entry shift table once perTool_FSGrepcall; on a failed alignment it slides the pattern by up tombytes instead of 1. For the patterns the model actually queries (TODO,function,class,FIXME,def,return), this is ~3-10× fewer text-byte reads.Case-insensitive is handled by folding text bytes through a 256-entry ASCII lower table built once per call — one branch instead of the old per-line
LowerCase(). The pattern itself is pre-lowered intoPatLowerthe same way as before.Output equivalence
Output is byte-identical to the old path except:
#13in the emitted line text. The oldStringReplacepass had hidden this; the byte walker now trims trailing#13explicitly.#13bytes (extremely rare; old Mac line endings) are no longer stripped from output. ripgrep treats them the same way.Test plan
make smoke— greenmake test— full aggregate green (existing + new)make test-fs-grep-tier5-6— 10 new tests insrc/tests/fs_grep_tier5_6_tests.paspin observable behaviour:ignore_casevia byte-fold tableAAAAvsAAAB,XAAAAY,AAAAA, etc.)¶path#hashheader still emitted sofs_edit_hashlinedownstream still parsesRelationship to #240
Both PRs touch the same function. #240 adds walk-time / per-file gating (deferred hash, blocked-dirs, NUL-sniff, size-cap). #241 (this PR) rewrites the inner scan loop. They compose cleanly — once one merges, the other will rebase with no semantic conflict.
Generated by Claude Code