continuedev / continuedev/continue

perf: avoid tokenizing lines that pruning discards

Open
#12,980 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

javascript kind:enhancement
Dominant language
TypeScript
Stars
36k
Forks
5.4k
PR merge metrics
No merged PRs in 30d

Description

Problem

Issue #4947 and PR #5310 removed repeated shift() / pop() work from pruneLinesFromTop and pruneLinesFromBottom. The current implementation still tokenizes every line up front, including lines that are immediately discarded when a large prompt is pruned to a small token budget.

On current main (d0a3c0b626b5bebc3bef4742eec05a0242be0bab), a deterministic 320-line fixture performs 641 Tiktoken.encode calls across top and bottom pruning. Traversing inward from the side that will be retained and stopping when the next line would exceed the budget reduces this to 88 calls (-86.3%).

At the 2,000-line scale from #4947, the same measurement is 4,001 calls on main and 86 with retained-side traversal (-97.9%). All nine runs at each revision produced the same count.

Correctness check

I compared the proposed traversal against current main over 580 top/bottom cases covering empty input, leading and trailing blank lines, newline boundaries, Unicode, single oversized lines, random multiline prompts, and zero or negative limits. All returned strings were byte-for-byte identical.

Proposed change

  • Accumulate retained lines from the bottom for pruneLinesFromTop.
  • Accumulate retained lines from the top for pruneLinesFromBottom.
  • Preserve the existing one-token newline accounting exactly.
  • Enable the existing focused pruning tests and keep the production change limited to the two function bodies.

Would this follow-up optimization be welcome?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating pruneLinesFromTop and pruneLinesFromBottom and the existing focused pruning tests. Compare the current tokenization flow with the stated retained-side traversal, paying attention to one-token newline accounting and edge cases. Done means the pruning results remain byte-for-byte identical while the focused measurements show substantially fewer Tiktoken.encode calls.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.