Skip to content

perf(lsp): skip import lexing outside strings - #1451

Merged
mattsse merged 1 commit into
paradigmxyz:mainfrom
0xKarl98:perf/lsp-completion-prefix
Sep 12, 2026
Merged

mattsse merged 1 commit into
paradigmxyz:mainfrom
0xKarl98:perf/lsp-completion-prefix

Conversation

@0xKarl98

@0xKarl98 0xKarl98 commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Towards OSS-738 ,

import_path_at handled every definition lookup by running the lexer from the beginning of the source file. Most requests come from ordinary code, where an import string is impossible.

  • Reuse the existing may_complete_string scan before invoking plain_string_at.
  • Return immediately when the cursor line has no quote and no escaped line continuation.
  • Keep the existing lexer and parser path for strings, comments containing quotes, and multiline continuations.

Benchmark evidence (cargo bench -p solar-lsp --features bench --bench lsp -- --noplot):

Case Before After Change
lsp/import-path/optimism-code 5.40–5.45 ms 3.36–3.42 ns ~1.6M× faster

The benchmark uses a 5.38 MB source with the cursor in ordinary code near the end of the file. Criterion compared a 20-sample baseline with a 30-sample optimized run.

@codspeed-hq

codspeed-hq Bot commented Sep 12, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×31,000

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 230 untouched benchmarks
⏩ 18 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
lsp/import-path[optimism-code] 59,084.2 µs 1.9 µs ×31,000

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing 0xKarl98:perf/lsp-completion-prefix (441e4b4) with main (b4727b7)

Open in CodSpeed

Footnotes

  1. 18 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@mattsse mattsse left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mattsse
mattsse merged commit 4447883 into paradigmxyz:main Sep 12, 2026
19 checks passed
@0xKarl98
0xKarl98 deleted the perf/lsp-completion-prefix branch September 12, 2026 10:01
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.

2 participants