Skip to content

fix(rewrite): read each pipeline from its first pipe - #5041

Open
KuSh wants to merge 1 commit into
rtk-ai:developfrom
KuSh:fix/pipeline-read-from-first-pipe
Open

KuSh wants to merge 1 commit into
rtk-ai:developfrom
KuSh:fix/pipeline-read-from-first-pipe

Conversation

@KuSh

@KuSh KuSh commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

Rewriting a compound command analyses every pipeline in it, and each analysis looked through the tokens from the start of the command to find its first pipe. A command of n pipelines read O(n^2) tokens.

The tokens are in the order of their offsets, so those before the first pipe are now skipped by bisection. The rewrite is unchanged.

command size develop this PR
ls + 49000 × ;| 98 KB 1607 ms 25 ms
ls + 9800 × ; ls | cat 98 KB 170 ms 36 ms
ls + 6500 × ; ls | cat | wc 98 KB 112 ms 23 ms
ls + 1000 × ; ls | cat 10 KB 11 ms 10 ms
ls + 100 × ; ls | cat 1 KB 7 ms 8 ms

Best of three runs of rtk rewrite, release builds. Commands of ordinary size don't change; this only shows on very long ones.

Test plan

  • cargo fmt --all, cargo clippy --all-targets, cargo test --all, and both with --no-default-features
  • A test counts the tokens read, with literal values for 100, 1000 and 10000 pipelines; it fails when the bisection is removed
  • rtk rewrite output and exit code identical to develop on every row above

🤖 Generated with Claude Code

Rewriting a compound command analyses every pipeline in it, and each
analysis looked through the tokens from the start of the command to find
the first pipe and the clause after it. A command of n pipelines read O(n^2)
tokens: a ladder of `;|` took 1.6 s at 98 KB.

The tokens are in the order of their offsets, so those before the first
pipe are skipped by bisection. The tokens read are counted by a test-only
counter, with literal values for 100, 1000 and 10000 pipelines.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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