Skip to content

Sourcemap generation consuming significant resources while sourcemaps are disabled #2265

@aem

Description

@aem

Description

When running tsgo --build on a project with source maps and declaration maps disabled, a significant amount of CPU and memory is spent on what seemingly should be unused source map-related functions.

tsgo setup

// <root>/tsconfig.json
//  ...
    "declaration": true,
    "emitDeclarationOnly": true,
    "sourceMap": false,
    "declarationMap": false,
    "emit": false,
//  ...

tsgo version: 7.0.0-dev.20251204.1

Details

After migrating our monorepo to tsgo with a significant local performance improvement, I went to test the new setup in CI and discovered worse performance than typescript@5.8.3 on a CI machine with 4 CPU cores and 16gb memory. I ran tsgo with profiling enabled (profiles attached below) and noticed (with the help of Claude) that source map emission accounted for ~60% of cumulative CPU time during compilation despite source maps and declaration maps both being disabled during the build:

         0     0% 90.69%    126.39s 29.24%  github.com/microsoft/typescript-go/internal/printer.(*Printer).emitSourceMapsAfterNode
         0     0% 90.69%    125.28s 28.99%  github.com/microsoft/typescript-go/internal/printer.(*Printer).emitSourceMapsBeforeNode

The memory profile looks much less interesting, I suspect the ~18GiB of memory consumed by our project is just related to having ~1mm LOC and heavy use of intersection types, but I'm surprised to see the source map printer consuming the majority of CPU time while all maps are disabled.

Profiles

82514-cpuprofile.pb.gz
82514-memprofile.pb.gz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions