Skip to content

Fix(memorization) issue 710 py lsp memoization#732

Open
LA-10 wants to merge 3 commits into
DeusData:mainfrom
LA-10:fix/issue-710-py-lsp-memoization
Open

Fix(memorization) issue 710 py lsp memoization#732
LA-10 wants to merge 3 commits into
DeusData:mainfrom
LA-10:fix/issue-710-py-lsp-memoization

Conversation

@LA-10

@LA-10 LA-10 commented Jul 1, 2026

Copy link
Copy Markdown

What does this PR do?

Fixes #710 index_repository hangs during the definitions pass on Python files with deeply chained method calls, consuming 800+ s and ~1.4 GB with no progress.

py_eval_expr_type (internal/cbm/lsp/py_lsp.c) recursively evaluates expression types with no memoization. Chained calls cause the same sub-chains to be re-evaluated at every level roughly O(2^N) in chain depth

Memoize py_eval_expr_type, keyed by node start byte. Each sub-expression is typed once, collapsing chain evaluation to O(depth). The original body is renamed _uncached and wrapped by a thin memoizing entry results identical, only redundant recomputation removed. Cache is arena-allocated per file (freed automatically).

Added pylsp_issue710_deep_call_chain_no_hang to tests/test_py_lsp.c a ~40-link chain that hangs on the old code and passes on the fix.

Checklist

  • Every commit is signed off (git commit -s) — required, CI rejects
    unsigned commits (DCO, see CONTRIBUTING.md)
  • Tests pass locally (make -f Makefile.cbm test)
  • Lint passes (make -f Makefile.cbm lint-ci)
  • New behavior is covered by a test (reproduce-first for bug fixes)
LA-10 added 3 commits July 1, 2026 08:02
Signed-off-by: LA-10 <lashuha@uwaterloo.com>
Signed-off-by: LA-10 <lashuha@uwaterloo.com>
Signed-off-by: LA-10 <lashuha@uwaterloo.com>
@LA-10 LA-10 requested a review from DeusData as a code owner July 1, 2026 05:21
@LA-10 LA-10 changed the title Fix/issue 710 py lsp memoization Jul 1, 2026
@DeusData DeusData added bug Something isn't working stability/performance Server crashes, OOM, hangs, high CPU/memory parsing/quality Graph extraction bugs, false positives, missing edges priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. labels Jul 1, 2026
@DeusData

DeusData commented Jul 1, 2026

Copy link
Copy Markdown
Owner

Huge thanks for opening this PR and for the work you put into it.

The maintainer shop is currently full, so this may sit for a bit before it gets a proper review. We will come back to this as soon as possible with real feedback; I wanted to make sure it did not sit unacknowledged in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working parsing/quality Graph extraction bugs, false positives, missing edges priority/high Needs near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker. stability/performance Server crashes, OOM, hangs, high CPU/memory

2 participants