Skip to content

unit-test builder: coverage phase became 20x+ slower since 22.1.5 (disableCodeSplitting forced for unit test builds) #33948

Closed

Description

@pascalmann

Command

test

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

22.1.4

Description

Since @angular/build 22.1.5, running the unit-test builder (Vitest runner) with coverage enabled on a large workspace shows the following pattern on our biggest libraries:

  • all tests complete normally (e.g. 27 spec files / 400 tests in ~35 s),
  • then the process keeps running at 100–160 % CPU and ~3–4 GB RSS with no output for more than 15 minutes — it looks like a hang. It is in fact the V8 coverage collection/remap phase.

On 22.1.4 the exact same target completes in 57 s end to end.

We bisected it to 22.1.5's fix(@angular/build): disable code splitting for unit test builds (unit-test/runners/vitest/build-options.ts now forces disableCodeSplitting: true). Our understanding of the mechanism: every spec file being an entry point, the test build now produces a single monolithic chunk containing the whole transitive module graph of the project (in our workspace: hundreds of internal libraries), and @vitest/coverage-v8 has to remap the source map of that entire chunk for every project, even though the coverage thresholds / report only concern the project's own files. With code splitting, the remap work was proportional to what each spec actually loaded.

Confirmed by re-applying disableCodeSplitting: false locally (pnpm patch): same project, same 22.1.6, 39 s end to end, identical coverage numbers.

Things we tried that do not help:

  • coverage.include: ['<projectRoot>/**'] in the Vitest runner config → coverage drops to 0 %: the filter seems to be applied to the bundled chunk paths before source-map remapping, so real hits are discarded and only unloaded files are reported (with Failed to parse ... README.md/component.html. Excluding it from coverage. warnings for every non-JS file in the project).
  • Excluding **/*.html from coverage → no measurable effect.
  • 22.1.6 → same behaviour.

We understand the motivation of the change (live ESM bindings read across a lazily-initialised shared chunk), but as it stands the trade-off makes coverage unusable on large workspaces: with 186 projects our CI job went from ~15 min to jobs timing out on the largest libraries. Possible directions:

  • expose the behaviour as a builder option (e.g. codeSplitting: boolean on the unit-test builder, defaulting to the current false), so workspaces that never hit the live-binding issue can opt back in;
  • or keep the monolithic build but scope the V8 coverage remap to the files that match coverage.include / the project root after remapping (i.e. remap only the source-map segments that resolve to included sources);
  • or emit the shared modules as eagerly-initialised chunks instead of disabling splitting altogether.

Minimal Reproduction

We do not have a small public reproduction yet — the effect is proportional to the size of the transitive module graph. Characteristics of the workspace that reproduces it reliably:

  • Nx 23.1.1 monorepo, ~5 100 non-spec TypeScript files under libs/, 186 projects with a test target;
  • tests run through @nx/angular:unit-test (which delegates to the @angular/build unit-test builder), Vitest runner, coverage: true, provider v8, reporters lcovonly + cobertura, thresholds scoped to <projectRoot>/**;
  • the affected library has 27 spec files / 400 tests and its lcov report lists 462 source files (88 of which belong to the library itself, the rest being transitive internal libraries).

Timings on the same machine (14 CPU, container, Node 22.22.3), same project, --configuration=ci (coverage on):

@angular/build tests coverage phase total
22.1.4 ~35 s ~20 s 57 s
22.1.6 ~35 s > 15 min (killed) —
22.1.6 + disableCodeSplitting: false (local patch) ~35 s ~5 s 39 s

Without coverage, 22.1.6 completes in ~30 s, so the tests themselves are unaffected. I am happy to run additional diagnostics (e.g. --dumpVirtualFiles, CPU profile of the coverage phase) or to try a patch.

Exception or Error

No exception — the process stays busy (100–160 % CPU, 3–4 GB RSS) with no output after the last test result. Killing it after 15+ minutes yields no report.

Your Environment

Angular CLI: 22.1.6
Node: 22.22.3
Package Manager: pnpm 11.24.0
OS: linux x64

@angular/build: 22.1.6 (regression introduced in 22.1.5)
@angular/core: 22.1.3
@angular/compiler-cli: 22.1.3
vitest: 4.1.11
@vitest/coverage-v8: 4.1.11
typescript: 6.0.3
jsdom: 30.0.1
nx / @nx/angular: 23.1.1

Anything else relevant?

No response

Activity

  1. added
    gemini-triaged
    on Aug 27, 2026
  2. added this to the needsTriage milestone on Aug 27, 2026
  3. added 9 commits that reference this issue on Aug 27, 2026
    8bce16a
    cfaa501
    2c03d17
    f0f034f
    3dd7aa1
    c3cefba
    78d8f1c
    ba0a2f0
    18757a9
  4. robsonbittencourt commented on Aug 28, 2026

    @robsonbittencourt

    Confirming this on a much smaller workspace, with two data points that may help: it also happens with @vitest/coverage-istanbul (not just v8), and here it is a hard OOM crash, not only a slowdown.

    Repo (public, reproduces as-is): https://github.com/robsonbittencourt/vgc-multicalc

    Setup: single-application workspace — no internal libraries — 167 spec files / 338 non-spec source files / ~213k lines, @angular/build:unit-test with the Vitest runner, provider: "istanbul".

    Angular CLI       : 22.1.6
    Angular           : 22.1.4
    @angular/build    : 22.1.6
    Node.js           : 24.16.0
    Package Manager   : npm 11.13.0
    OS                : linux x64 (Ubuntu 24.04, 12 cores, 31 GB RAM)
    vitest                    : 4.1.11
    @vitest/coverage-istanbul : 4.1.11
    jsdom                     : 30.0.1
    typescript                : 6.0.3
    

    Version bisection. Only @angular/build was changed between runs; @angular/cli 22.1.6, the framework, vitest, jsdom and the coverage provider stayed fixed. Same suite, same machine, ng test --coverage --watch=false:

    @angular/build result
    22.1.4 ✅ 167 files / 3812 tests pass, 71 s end to end, coverage reported (99.98% statements)
    22.1.5 ❌ OOM after 130 s, before any test runs
    22.1.6 ❌ OOM after 124 s, before any test runs

    Without coverage, 22.1.6 runs the suite fine in ~97 s, so it is specific to the coverage path.

    This matches your bisection: disableCodeSplitting: true is absent from src/builders/unit-test/ in the 22.1.4 tarball and present in both 22.1.5 and 22.1.6.

    The crash on 22.1.6:

     RUN  v4.1.11
          Coverage enabled with istanbul
    
    <--- Last few GCs --->
    [15722:0x29af4000]   121759 ms: Mark-Compact 4042.8 (4179.9) -> 4042.8 (4178.9) MB, pooled: 6 MB, 121.18 / 0.00 ms  (average mu = 0.863, current mu = 0.643) allocation failure; scavenge might not succeed
    [15722:0x29af4000]   121993 ms: Mark-Compact 4091.3 (4227.4) -> 4091.2 (4227.4) MB, pooled: 6 MB, 124.59 / 0.00 ms  (average mu = 0.781, current mu = 0.468) allocation failure; scavenge might not succeed
    
    FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
    Aborted (core dumped)
    

    Memory sampled every 2 s (sum of RSS across ng test + vitest workers + esbuild):

    t (s) total RSS largest process procs
    0 38 MB 31 MB 3
    20 1905 MB 1621 MB 5
    30 6496 MB 2202 MB 16
    60 7095 MB 3557 MB 16
    90 9675 MB 6137 MB 16
    120 11255 MB 7727 MB 16
    124 — — OOM

    Peak single process 7.7 GB, peak total 11.3 GB, on a machine with ~24 GB available — the ceiling being hit is V8's default ~4.3 GB heap, not host memory.

    Two things that may narrow the mechanism down:

    1. Switching to @vitest/coverage-istanbul does not avoid it. In Code splitting change introduced in @angular/build@22.1.5 breaks vitest cobertura report #33938 the suggested workaround was moving off coverage-v8; this workspace has used istanbul throughout and still OOMs. So the cost is not confined to V8 byte-offset remapping — the istanbul path hits it too, which points at the monolithic chunk itself rather than the remapping strategy.

    2. The amplifier here is file size, not project count. There are no internal libraries to fan out over. What this app does have is a few large data-only modules — plain object literals, no branches:

      1.5 MB / ~83k lines  src/domain/data/pokemon-moveset.ts
      0.4 MB               src/domain/data/moveset-data.ts
      0.4 MB               src/domain/data/pokemon-data.ts
      

      With code splitting disabled these land in the single shared chunk every spec pulls in. That suggests a minimal repro could be built from one generated multi-MB data file plus a handful of specs, which would be far easier to package than a 186-project monorepo.

    Possibly related, same version jump: on 22.1.5/22.1.6 vi.resetModules() no longer recycles modules for the unit-test builder. A spec that calls vi.resetModules() in beforeEach and then await import("./some-module") gets the module instance evaluated in the first test, so a module reading localStorage at import time keeps its initial value for the rest of the file. On 22.1.4 the same spec passes (167/167); on 22.1.6 it fails (166/167). I have not verified whether this shares a root cause with the code-splitting change — happy to file it separately if it is unrelated.

    A codeSplitting builder option as you proposed would work for us. Happy to test a patch, or to put together that minimal repro if it would help.

  5. added a commit that references this issue on Aug 28, 2026
    0e23fea
  6. added a commit that references this issue on Aug 28, 2026
    1c9b1af
  7. added a commit that references this issue on Aug 28, 2026
    4b8c62a
  8. angular-automatic-lock-bot commented on Oct 20, 2026

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  9. locked and limited conversation to collaborators on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: @angular/buildgemini-triagedseverity5: regression

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions