Skip to content

Allow injection queries to declare a source prefilter - #42

Closed
matoous wants to merge 1 commit into
helix-editor:masterfrom
mitos-editor:perf/injection-source-pattern
Closed

matoous wants to merge 1 commit into
helix-editor:masterfrom
mitos-editor:perf/injection-source-pattern

Conversation

@matoous

@matoous matoous commented Oct 20, 2026 •

Copy link
Copy Markdown

A small edit can rerun an injection query across a large syntax tree even when the source cannot contain a match. In the editor's JSON workload, looking for comment injections dominates otherwise incremental whitespace edits.

Add an optional injection.source-pattern property. It is a necessary condition supplied by the query author: if every injection pattern has a guard and none of those regexes matches the source, skip the injection query traversal. The regex reads the rope directly. Patterns without a guard retain the existing behavior, and existing injections are still mapped and pruned when the last marker is removed.

For example, JSON's comment injection can use (#set! injection.source-pattern "/[/*]"). Text without either comment opener cannot contain a comment injection. A marker inside a string is a safe false positive and falls back to the normal query. An incorrect guard can suppress real injections, so the README documents that contract; no existing query behavior changes unless it opts in.

Comment-free JSON array Without source guard With source guard
1,000 rows: insert and inverse 1.59 ms 0.556 ms
10,000 rows: insert and inverse 17.04 ms 3.39 ms
100,000 rows: insert and inverse 195.53 ms 38.17 ms

Both sides use the same patched dependency binary; only the JSON injection query property changes. The comparison uses the Mitos release-mode JSON probe: insert one space in the middle of a comment-free array and apply its inverse, taking the median of 11 pairs. It measures the full synchronous syntax update pair, not typing-to-screen latency. The editor change is mitos-editor/mitos#574 and adds the JSON query property. Its ignored json_update_performance test contains the probe. Documents containing a possible marker still execute the existing injection query.

Validation: all 45 upstream tests passed, formatting passed, and focused Clippy passed with warnings denied. Tests cover comment insertion/removal, a mixed guarded/unguarded query, invalid regexes, a marker crossing rope chunks, and a marker inside a string.

cargo test --locked -p tree-house
cargo fmt --all --check
cargo clippy --locked --no-deps -p tree-house --all-targets -- -D warnings

@matoous

matoous commented Oct 20, 2026

Copy link
Copy Markdown
Author

Moved this proposal to our fork: mitos-editor#1.

@matoous matoous closed this Oct 20, 2026
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