perf(lsp): semantic tokens up to 10x faster, symbols up to 2.8x on large files - #211
Merged
Merged
Conversation
…rge files Semantic tokens looked each use's binder up by scanning every binder of the document, with no early exit; they now look it up in a trie keyed by line (locals) or by name hash (items and constructors) built once per request, each leaf in source order, so the answer is the scan's. Enc.cols now reads a document with no char past U+FFFF as utf-32, where UTF-16 agrees, so a position crosses the boundary without walking to its line; the new law enc_narrow (BOLT-LSP-7) proves that agreement both ways. Bind.kind_at and Bind.kind_of_item had no other caller and are gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… no wide char enc_narrow proves it; it was tagged BOLT-LSP-7, whose row neither named it nor states it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…points Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First LSP perf pass, following the baseline taken after #201 (which already made every LSP request 2–4x faster than before it).
What changed
src/lsp/semantic.bend): each use's binder was found by scanning every binder of the document with no early exit (Bind.kind_at,Bind.kind_of_item), which is O(uses × binders). The binders are now indexed once per request in a binary trie on the low 16 bits of a key: a local's line, or a hash of an item's or constructor's name. Each leaf keeps source order, so a lookup returns exactly what the old front-to-back scan returned.Bind.kind_at/Bind.kind_of_itemhad no other caller and are deleted.src/lsp/enc.bend): every position sent or read looked its line up withList.getfrom line 0, even under utf-32.Enc.colsnow checks the text once, and a document with no char past U+FFFF converts as utf-32, where UTF-16 agrees.out/intonever touch the lines under utf-32.enc_narrowinsrc/lsp/LAWS.bend: on a line with no character past U+FFFF, a column counted in UTF-16 units equals the column counted in characters, both sent and read. That is what makes the utf-32 shortcut safe.LAWS.bendare human-owned, so the row's wording and the law need your review. No existing law changed, and every proof still checks.Measurements
bolt lsp --gpu offdriven like an editor; best of 2 runs, in ms.src/syntax/bind.bendsrc/LAWS.bendsrc/syntax/PROOF.bendsrc/rules/LAWS.bendsrc/rules/PROOF.bendChange (lint), hover, definition, completion and references are unchanged within noise. Their cost is re-linting and re-binding the whole document on every request, not position conversion. That is the next pass: cache each document's analysis, and skip superseded
didChanges.Verification
bend src/lsp/PROOF.bend: All terms check.bolton the tree: 0 errors. The new index defs add L001 warnings. They are left in, not noqa'd, because a lookup must always return what a scan of the binders returns, so a law should cover them eventually. The rest of semantic classification (classify,data, …) already warns on main for the same reason.🤖 Generated with Claude Code