Skip to content

perf(compile): lower rules-phase peak memory - #937

Merged
kvlonge merged 1 commit into
mainfrom
perf/rules-phase-memory
Oct 4, 2026
Merged

kvlonge merged 1 commit into
mainfrom
perf/rules-phase-memory

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Why

Since native analysis runs in parallel at 10k models (#934), the compile's memory peaks in the rules phase. Profiling showed lint keeping a second copy of every SQL file's text and ~280 MB of freed-but-held allocator memory before rules start (CHI-441).

Changes

  • Lint and SQL-rules file collection reuse the text discovery already holds when it is identical to a fresh read, instead of keeping a second copy.
  • Return freed memory to the OS (glibc malloc_trim) at the start of rules evaluation; a no-op on other platforms.
  • Tighten the dense 10k peak-RSS guard from 3.5 to 3.25 GiB.

Verification

  • Dense 10k --no-cache, 4 GiB cgroup (base → head medians): main peak 2822 → 2404 MB, process group 2965 → 2586 MB; 3k −9 to −11%. CPU unchanged; fingerprints and diagnostics identical.
  • Unit and run_lint integration tests for text reuse.
  • One independent review; make test, make check-ci.

Share SQL file text that discovery already holds instead of keeping a second
copy for SQL lint and SQL Rules, and return freed glibc heap pages to the OS
before the rules phase starts, where native rules, SQL lint and the custom-rule
host overlap. Text is only shared when it is byte-for-byte identical to the
fresh read, so findings and diagnostics are unchanged.

Dense 10,000-model --no-cache main-process peak drops about 15%, so the dense
guard tightens from 3.5 GiB to 3.25 GiB.
@kvlonge
kvlonge enabled auto-merge (squash) October 4, 2026 10:17
@kvlonge
kvlonge merged commit 6d35706 into main Oct 4, 2026
30 checks passed
@kvlonge
kvlonge deleted the perf/rules-phase-memory branch October 4, 2026 10:36
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