Skip to content

perf: shrink index allocations after scan — reduce steady-state RSS (#261)#262

Merged
justrach merged 1 commit intorelease/v0.2.57from
perf/261-trigram-rss
Apr 13, 2026
Merged

perf: shrink index allocations after scan — reduce steady-state RSS (#261)#262
justrach merged 1 commit intorelease/v0.2.57from
perf/261-trigram-rss

Conversation

@justrach
Copy link
Copy Markdown
Owner

Summary

Add shrinkPostingLists() to TrigramIndex and shrinkAllocations() to WordIndex. Both release ArrayList over-allocation after initial scan completes, reducing steady-state RSS for long-running MCP servers.

What was tried

Approach Peak RSS Recall Verdict
Baseline v0.2.56 3,678MB 52/52
Content cache limit (PR#260) 3,415MB 52/52 Merged
CLOCK eviction cache (PR#259) 5,595MB 52/52 Reverted (+57% RSS)
Posting cap at 512 3,172MB 2/52 Reverted (recall loss)
Shrink-only (this PR) 3,415MB 52/52 Safe, helps MCP steady-state

Peak RSS during cold indexing is unchanged (3,415MB). The peak is dominated by GPA page retention from alloc/free churn during indexing — the shrink runs after the peak. Further peak reduction needs a custom allocator or pre-sized flat storage (tracked in #261).

Test plan

  • All existing tests pass
  • Recall: 52/52 for handleRequest on openclaw — no false negatives
  • No speed regression (5.54s vs 5.24s — within variance)

🤖 Generated with Claude Code

Add shrinkPostingLists() to TrigramIndex and shrinkAllocations() to
WordIndex. Both release ArrayList over-allocation (capacity > length)
after initial scan completes. This reduces steady-state RSS for
long-running MCP servers by reclaiming ~50% of ArrayList capacity waste.

Note: peak RSS during cold indexing is unchanged — the shrink runs
after the peak. The peak is dominated by GPA page retention from
alloc/free churn during indexing. Further reduction would require
a custom allocator or pre-sized flat storage.

Benchmark (openclaw, 13,867 files):
  Peak RSS unchanged (3,415MB) — expected, shrink runs after peak
  Recall: 52/52 for 'handleRequest' — no false negatives
  An earlier cap approach (MAX_POSTINGS=512) saved 243MB peak but
  dropped recall to 2/52 — reverted in favor of shrink-only

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@justrach justrach merged commit 42e8700 into release/v0.2.57 Apr 13, 2026
@github-actions
Copy link
Copy Markdown

Benchmark Regression Report

Threshold: 10.00%

Tool Base (ns) Head (ns) Delta Status
codedb_bundle 661821 651612 -1.54% OK
codedb_changes 110504 108500 -1.81% OK
codedb_deps 32603 29584 -9.26% OK
codedb_edit 24801 23368 -5.78% OK
codedb_find 140785 140944 +0.11% OK
codedb_hot 148115 149699 +1.07% OK
codedb_outline 429499 447962 +4.30% OK
codedb_read 141807 147367 +3.92% OK
codedb_search 285470 286707 +0.43% OK
codedb_snapshot 4552851 4533451 -0.43% OK
codedb_status 258274 257126 -0.44% OK
codedb_symbol 63334 61371 -3.10% OK
codedb_tree 91542 88995 -2.78% OK
codedb_word 93079 90669 -2.59% OK

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.

1 participant