Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): skip unnecessary thread search snippet segmentation #47404

MergedUtkarshUsername(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/47404/headmerged by Yash-Singh1(GitHub profile, opens in a new tab) View on GitHub

UtkarshUsername(GitHub profile, opens in a new tab)commented

Problem

The grapheme fixes in #47038, #47027 and #47109 made thread search segment plain ASCII snippets and scan back through long runs of Han text before cutting a snippet.

Change

Use adjacent ASCII or basic Han characters to identify safe cuts. Keep CRLF together at the raw cut. Use Intl.Segmenter for ambiguous cuts and look up the final grapheme directly.

Verification

InstaBox passed 39 ThreadSearch tests and check:changed with 41 tests. An isolated Node 26 comparison against dcc96ebd84 found identical snippets in 21,096 cases. For the capture fixtures, call buildSearchSnippet directly with the offset of zebraquokka. On the current base e573bc473e and PR head 70168c3a18, a 9,372-character ASCII message used two segmenter calls before and zero after. A message with 10,000 Han characters followed by zebraquokka used 9,978 character reads before and three after. Both fixtures fit below the message limit and returned identical snippets. Across six trials per version, 4,000 ASCII snippets took a median of 164 ms before and 23 ms after. The trial measured snippet construction alone.

Fixes #47457.

GPT-6.2 Sol via Codex.

    1. Pushed70168c3

    2. The automated pipeline stopped on this pull request and will not merge it:

      the capture step could not show the problem on the base commit, so there is nothing to prove fixed.

      Create a synthetic project and two Replay multi-turn threads. Submit 9,372-character ASCII repeated-sentence text with zebraquokka in the middle, and 10,000 Han characters followed by zebraquokka. Search zebraquokka using orchestration.searchThreads with limit 50, requiring two matches. Warm up 1,000 requests, then measure 13 batches of 400 sequential full searches; require every response to equal the initial response. Compare returned snippets between commits. Separately attempt one-million-Han input through real CLI and user-message RPC; both reject at 120,000 characters. The full original ASCII phrase was unavailable, so a same-length synthetic sentence was used.

      It stays open for a person to finish or close.

    3. juliusmarminge added labelstakeover:blocked

    4. juliusmarminge removed labelstakeover:in-progress

    5. Following up on the capture test above. Could it call buildSearchSnippet(text, text.indexOf("zebraquokka")) directly on the base and PR commits? Use the same two inputs: the 9,372-character ASCII message and the message with 10,000 Han characters followed by zebraquokka. Assert that the returned snippets are identical, then count Intl.Segmenter.prototype.segment calls in the ASCII case and String.prototype.charCodeAt calls in the Han case. Count only calls during snippet construction.

      I ran that comparison on base e573bc473e and PR head 70168c3a18 and updated the PR description. Both inputs fit under the 120,000-character limit and produced identical snippets. The ASCII case went from 2 segmenter calls to 0. The Han case went from 9,978 character reads to 3.

      The full-search test can still check that the RPC returns the same results and snippets. The counts above measure the work this PR removes during snippet construction. An end-to-end speedup remains unverified.

Sign in to join this conversation.