Does a Language Server Save Tokens for Coding Agents? A Measurement Methodology and Preliminary Study
Does a Language Server Save Tokens for Coding Agents? A Measurement Methodology and Preliminary Study
语言服务器能为编程智能体节省 Token 吗?一种测量方法与初步研究
Abstract: Coding agents spend most of their context budget on retrieval. Lexical retrieval (grep) is universal, instant, and zero-setup, but noisy: it cannot tell a definition from a call from a comment. Semantic retrieval via the Language Server Protocol (LSP) is precise and typed, but needs a running, indexed server and pays a per-symbol round-trip. The claim that semantic retrieval is more token-efficient is, we find, asserted almost everywhere and measured almost nowhere: no public source isolates the LSP-vs-lexical token delta for an agent at equal task-success.
摘要: 编程智能体(Coding agents)将大部分上下文预算花费在检索上。词法检索(grep)具有通用、即时且无需配置的特点,但存在噪声:它无法区分定义、调用和注释。通过语言服务器协议(LSP)进行的语义检索虽然精确且具有类型信息,但需要运行并索引服务器,且每次符号查询都需要往返通信。我们发现,关于“语义检索更节省 Token”的说法几乎随处可见,却鲜有测量数据支持:目前没有任何公开来源能在任务成功率相等的前提下,隔离出智能体在使用 LSP 与词法检索时的 Token 差异。
This paper formalizes the question with one metric (tokens-to-success), specifies a five-arm ablation isolating semantic retrieval from confounds, maps three pre-stated failure modes onto measurable variables, and reports a preliminary study (Python and TypeScript repos; Claude Opus 4.8, Sonnet 4.6, Haiku 4.5).
本文通过单一指标(成功所需 Token 数)将该问题形式化,指定了五组消融实验以将语义检索与干扰因素隔离开来,将三种预设的失败模式映射为可测量变量,并报告了一项初步研究(涵盖 Python 和 TypeScript 代码库;模型包括 Claude Opus 4.8、Sonnet 4.6 和 Haiku 4.5)。
The answer is conditional and usually negative. On symbol-named localization the LSP costs tokens (+6% to +118%) and the agent ignores it when free. On reference-completeness it buys precision but not token savings and cannot raise the recall ceiling set by agent thoroughness; it saves tokens only for the weakest model. Tool choice is task-dependent: models default to grep on localization (0-6% semantic use) but reach for the LSP about half the time on reference tasks, unprompted.
研究结果是有条件的,且通常为否定。在符号定位任务中,LSP 会增加 Token 消耗(+6% 到 +118%),且当免费使用时,智能体往往会忽略它。在引用完整性方面,它虽然提升了精度,但并未节省 Token,也无法突破由智能体自身严谨性决定的召回率上限;它仅对最弱的模型有节省 Token 的效果。工具选择取决于任务:模型在定位任务中默认使用 grep(语义使用率仅 0-6%),但在引用任务中,约有一半时间会自发选择使用 LSP。
On edits scored by real test execution the gap is starkest: grep solves multi-file renames perfectly, a location-only LSP fails three-quarters of them by missing a call site, and even a complete, index-warmed, text-enriched LSP (each reference’s line inline, as production LSP-MCP servers do) recovers most of the gap but cannot close it, since a rename must touch comments and strings that semantic references exclude. The implication is not LSP-always but an adaptive router keyed on task class, model capability, and lexical noise.
在通过实际测试执行评分的编辑任务中,差距最为明显:grep 能完美解决多文件重命名问题,而仅提供位置信息的 LSP 因遗漏调用点,导致四分之三的任务失败;即使是完整、已预热索引且包含文本增强的 LSP(如生产环境中的 LSP-MCP 服务器,将每处引用的行内联),也只能弥补大部分差距,却无法完全消除,因为重命名必须触及语义引用所排除的注释和字符串。结论并非“始终使用 LSP”,而是应根据任务类别、模型能力和词法噪声进行自适应路由。