Skip to content

Skip .worktrees and .phpstan when building the CPG - #1

Open
Braindea7 wants to merge 1 commit into
Hackbard:mainfrom
Braindea7:fix/exclude-worktrees-and-phpstan
Open

Skip .worktrees and .phpstan when building the CPG#1
Braindea7 wants to merge 1 commit into
Hackbard:mainfrom
Braindea7:fix/exclude-worktrees-and-phpstan

Conversation

@Braindea7

@Braindea7 Braindea7 commented Aug 14, 2026

Copy link
Copy Markdown

Two directory kinds slip past DEFAULT_EXCLUDES/IGNORE_DIRS and hurt the build on a Laravel monorepo.

.worktrees/ holds full second checkouts — the layout git worktree add gets pointed at most often. Every symbol gets indexed once per worktree: in the repo I measured this on, 13,344 of 18,630 indexed files came from three worktrees, so lmc find returned each hit four times and impact overstated the blast radius by the same factor, mixing in stale branch states that no longer exist anywhere. Excluding it cut the index from 18,630 to 5,286 files.

.phpstan/ is PHPStan's cache. Its resultCache.php reaches double-digit MB (23 MB in this repo); php2cpg reads the parser output into memory in one go (IOUtils.contentFromBufferedSource) and dies with java.lang.OutOfMemoryError, which surfaces as joern-parse exit 1 and a silent fallback to the tree-sitter index.

To be precise about what this PR does and does not fix: excluding .phpstan was necessary but not sufficient in my repo. It also carries a vendored legacy tree with 1.5 MB font arrays that contributes to the same OOM, and that directory name is project-specific, so it has no business in a shared list. Measured:

excluded result
.phpstan only OOM after 44 s
legacy tree only OOM after 47 s
both exit 0 after 19 s

So this PR removes one of the two causes and the duplicate-indexing problem outright. The project-specific half is what #2 addresses, via an exclude: key in lumos.yml — with both in place, lmc build over 4,493 files completes the Joern CPG in 18 s instead of aborting.

Existing tests stay green: tests/test_joern_parse_excludes.py counts --exclude against len(DEFAULT_EXCLUDES), so the new entries do not break it.

Two directory kinds slipped past DEFAULT_EXCLUDES/IGNORE_DIRS and broke the
build on a Laravel monorepo:

- `.worktrees/` holds full second checkouts (the layout `git worktree add`
  gets pointed at most often). Every symbol was indexed once per worktree —
  in the repo this was measured on, 13,344 of 18,630 indexed files came from
  three worktrees, so `lmc find` returned every hit four times and `impact`
  overstated the blast radius by the same factor, mixing in stale branch
  states that no longer exist anywhere.

- `.phpstan/` is PHPStan's cache. Its `resultCache.php` reaches double-digit
  MB (23 MB here); php2cpg reads the parser output into memory in one go
  (IOUtils.contentFromBufferedSource) and dies with java.lang.OutOfMemoryError.

Measured on the same repo, `lmc build` on 4,493 files: previously it aborted
with `joern-parse exit 1` and fell back to the tree-sitter index, now the
Joern CPG completes in 18 s.
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