Skip to content

perf: MCP/Skills auto improvements#2

Open
art049 wants to merge 5 commits into
codspeed-wizard-1773436314243from
perf/linter-resolve-qualified-name
Open

perf: MCP/Skills auto improvements#2
art049 wants to merge 5 commits into
codspeed-wizard-1773436314243from
perf/linter-resolve-qualified-name

Conversation

@art049

@art049 art049 commented Mar 16, 2026

Copy link
Copy Markdown
Owner

Summary

Test Plan

@codspeed-hq

codspeed-hq Bot commented Mar 16, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 16.03%

⚡ 7 improved benchmarks
✅ 23 untouched benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
linter/default-rules[pydantic/types.py] 2.2 ms 1.9 ms +16.03%
linter/all-with-preview-rules[large/dataset.py] 23.2 ms 20.7 ms +12.35%
linter/all-rules[pydantic/types.py] 8.8 ms 7.7 ms +14.85%
linter/default-rules[numpy/ctypeslib.py] 1,045.9 µs 948.2 µs +10.3%
linter/default-rules[numpy/globals.py] 212.4 µs 187.5 µs +13.31%
linter/all-with-preview-rules[pydantic/types.py] 10.4 ms 9.2 ms +12.92%
linter/all-rules[large/dataset.py] 19.4 ms 17 ms +13.75%

Comparing perf/linter-resolve-qualified-name (c85edb8) with codspeed-wizard-1773436314243 (32d6563)

Open in CodSpeed

claude and others added 4 commits March 17, 2026 13:32
…ant AST walks

Replace iterator-chain-based QualifiedName construction with direct
slice concatenation via new `from_two_parts` method, and add a fast
path for simple name expressions (no attribute access) that skips
UnqualifiedName::from_expr entirely.

Walltime improvements: 1.3-3.3% across all-rules linter benchmarks.


Co-Authored-By: CodSpeed <no-reply@codspeed.io>
Two optimizations for the resolve_qualified_name hot path:

1. from_two_parts: directly construct inline SegmentsStack for the common
   case (≤8 segments), bypassing the SegmentsVec API overhead (match on
   variant, capacity checks, spill handling on each extend_from_slice).

2. resolve_qualified_name: extract attribute tail segments directly from
   the AST for single and double attribute access (e.g., os.path,
   os.path.join), avoiding the cost of UnqualifiedName::from_expr
   entirely for these common cases.

Walltime benchmarks show -4.3% to -5.5% improvement on large files.


Co-Authored-By: CodSpeed <no-reply@codspeed.io>
Two optimizations targeting physical line processing:

1. bidirectional_unicode: Skip the contains() check for ASCII-only lines,
   since all bidirectional Unicode characters are non-ASCII. The is_ascii()
   check is SIMD-accelerated and handles the common case immediately.

2. LineWidthBuilder::add_str: For ASCII text, iterate bytes directly
   instead of chars, avoiding per-character unicode_width lookups. ASCII
   characters always have width 1 (except tabs and newlines which are
   handled explicitly).

Walltime benchmarks show -1% to -3% additional improvement across all
test files, with the largest gains on large/dataset.py.


Co-Authored-By: CodSpeed <no-reply@codspeed.io>
- Add super-fast path in `add_str` using `memchr3` to skip byte-by-byte
  iteration for ASCII text without tabs/newlines/CR (just add byte length)
- Add tighter early exit in `Overlong::try_from_line`: for any text,
  display width ≤ UTF-8 byte length (except tabs), so lines with byte
  length ≤ limit and no tabs cannot be overlong
- Hoist `indented_form_feed` rule check outside the per-line loop in
  `check_physical_lines`


Co-Authored-By: CodSpeed <no-reply@codspeed.io>
@art049 art049 force-pushed the perf/linter-resolve-qualified-name branch from cf1bdf5 to c720d4e Compare March 17, 2026 12:48
- Pre-allocate nodes, bindings, references, branches, scopes, and
  definitions in SemanticModel based on estimated token count
- Pre-allocate resolved_names and shadowed_bindings FxHashMaps
- Pre-allocate global scope bindings map (256 slots for Python builtins)
- Add Scopes::with_capacity and Definitions::for_module_with_capacity
- Pre-allocate deferred visit (functions) and analyze (scopes) Vecs
- Cache ambiguous unicode confusable settings check outside loop

Co-Authored-By: CodSpeed <no-reply@codspeed.io>
@art049 art049 force-pushed the perf/linter-resolve-qualified-name branch from c720d4e to c85edb8 Compare March 17, 2026 12:52
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