loader: speed up line length calculation used by moduleProvider by zeusdeux · Pull Request #50969 · nodejs/node

@nodejs-github-bot added the needs-ci

PRs that need a full CI run.

label

Nov 29, 2023

@zeusdeux zeusdeux changed the title loader: Speed up line length calculation used by moduleProvider loader: speed up line length calculation used by moduleProvider

Nov 29, 2023

@anonrig anonrig added author ready

PRs that have at least one approval, no pending requests for changes, and a CI started.

request-ci

Add this label to start a Jenkins CI on a PR.

labels

Nov 29, 2023

ljharb

GeoffreyBooth

@GeoffreyBooth GeoffreyBooth removed the author ready

PRs that have at least one approval, no pending requests for changes, and a CI started.

label

Nov 29, 2023

aduh95

zeusdeux

aduh95

@zeusdeux

When using a loader, for say TypeScript, the esm loader invokes the
`lineLengths` function via `maybeCacheSourceMap` when sourcemaps are
enabled. Therefore, `lineLengths` ends up getting called quite often
when running large servers written in TypeScript for example. Making
`lineLengths` faster should therefore speed up server startup times
for anyone using a loader with node with sourcemaps enabled.

The change itself is fairly simple and is all about removing creation
of unnecessary memory and iterating the whole source content only once
with the hope of making the function cache friendly.

H4ad

H4ad approved these changes Dec 2, 2023

@H4ad H4ad added request-ci

Add this label to start a Jenkins CI on a PR.

author ready

PRs that have at least one approval, no pending requests for changes, and a CI started.

and removed commit-queue-failed

An error occurred while landing this pull request using GitHub Actions.

labels

Dec 2, 2023

JakobJingleheimer

@zeusdeux zeusdeux deleted the speed-up-source-map-processing branch

December 3, 2023 00:44

targos pushed a commit that referenced this pull request

Dec 4, 2023
When using a loader, for say TypeScript, the esm loader invokes the
`lineLengths` function via `maybeCacheSourceMap` when sourcemaps are
enabled. Therefore, `lineLengths` ends up getting called quite often
when running large servers written in TypeScript for example. Making
`lineLengths` faster should therefore speed up server startup times
for anyone using a loader with node with sourcemaps enabled.

The change itself is fairly simple and is all about removing creation
of unnecessary memory and iterating the whole source content only once
with the hope of making the function cache friendly.

PR-URL: #50969
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Jacob Smith <jacob@frende.me>

richardlau pushed a commit that referenced this pull request

Mar 25, 2024
When using a loader, for say TypeScript, the esm loader invokes the
`lineLengths` function via `maybeCacheSourceMap` when sourcemaps are
enabled. Therefore, `lineLengths` ends up getting called quite often
when running large servers written in TypeScript for example. Making
`lineLengths` faster should therefore speed up server startup times
for anyone using a loader with node with sourcemaps enabled.

The change itself is fairly simple and is all about removing creation
of unnecessary memory and iterating the whole source content only once
with the hope of making the function cache friendly.

PR-URL: #50969
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Jacob Smith <jacob@frende.me>