perf: Implement terminal reuse for tags sharing the same content regex#169
perf: Implement terminal reuse for tags sharing the same content regex#169
Conversation
Co-authored-by: Ki-Seki <60967965+Ki-Seki@users.noreply.github.com>
Co-authored-by: Ki-Seki <60967965+Ki-Seki@users.noreply.github.com>
|
@copilot Add new test cases to reflect this change |
- test_build_cfg_single_tag_no_reuse: Edge case with single tag - test_build_cfg_all_unique_patterns: All tags with different patterns - test_build_cfg_many_tags_same_pattern: High reuse scenario with 10 tags - test_build_cfg_complex_regex_patterns: Complex regex with special chars - test_build_cfg_terminal_reuse_validates: Validation check for reused terminals Co-authored-by: Ki-Seki <60967965+Ki-Seki@users.noreply.github.com>
Added 5 additional test cases in commit 1dcc04b:
All 9 tests pass (4 original + 5 new). |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@copilot I have pushed other commits. So you may change the PR desc correspondingly. |
Updated the PR description to reflect your changes: |
There was a problem hiding this comment.
Pull request overview
Improves build_cfg() performance by reusing LLGuidance terminal rules when multiple tags share the same content regex, reducing redundant grammar output (especially for the default /(?s:.*)/ pattern).
Changes:
- Switch terminal naming from per-tag (
M_i) to per-unique-pattern (T_i). - Deduplicate identical regex patterns via a
unique_pattern_terminalsmapping and reuse terminals across tags. - Update
build_cfg()tests and thebuild_cfg()docstring example to match the new grammar output.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/gimkit/dsls.py |
Implements terminal reuse/deduplication and updates the docstring example to reflect T_i terminals. |
tests/test_dsls.py |
Updates expected grammar strings to use T_i terminals and adds a repeated-regex assertion case. |
Each tag in
build_cfg()was generating its own terminal rule (M_i), even when multiple tags shared identical regex patterns. This created redundant grammar rules, particularly problematic for the common `/(?s:.*)/" default pattern.Changes
M_i(per-tag) →T_i(per-unique-pattern)unique_pattern_terminalsdictT_iterminal namingImpact
10 tags with default pattern: 10 terminals → 1 terminal (90% reduction)
Testing
Updated test expectations and added comprehensive test case for terminal reuse with complex patterns:
\d{4}-\d{2}-\d{2}) correctly reuse terminalT_0\d{2}:\d{2}:\d{2}) correctly reuse terminalT_1All tests verify that the optimization maintains correctness while improving efficiency.
Original prompt
/(?s:.*)/) #168✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.