Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(npm): Speed-up getting the remote package details #10059

Merged
merged 1 commit into from
Mar 21, 2025

Conversation

fviernau
Copy link
Member

@fviernau fviernau commented Mar 19, 2025

Obtaining the package details via npm info is a performance bottleneck of ORT's NPM package manager. Request the package details for all packages upfront, in parellel to reduce execution time. Experiments on a development machine show that execution of NpmFunTest now takes 1 min 13 sec instead of 3 min 47 sec.

Fixes: #9950.

before

Screenshot from 2025-03-19 13-32-26

after

Screenshot from 2025-03-19 13-18-31

@fviernau fviernau requested a review from a team as a code owner March 19, 2025 12:41
@fviernau fviernau force-pushed the npm-view-concurrency branch from c692187 to adc2520 Compare March 19, 2025 12:44
Copy link

codecov bot commented Mar 19, 2025

Codecov Report

Attention: Patch coverage is 88.88889% with 2 lines in your changes missing coverage. Please review.

Project coverage is 69.64%. Comparing base (42af1f5) to head (30bfebe).
Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
...s/package-managers/node/src/main/kotlin/npm/Npm.kt 87.50% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #10059      +/-   ##
============================================
+ Coverage     69.57%   69.64%   +0.07%     
- Complexity     1462     1464       +2     
============================================
  Files           270      270              
  Lines          9665     9681      +16     
  Branches       1025     1028       +3     
============================================
+ Hits           6724     6742      +18     
+ Misses         2491     2489       -2     
  Partials        450      450              
Flag Coverage Δ
funTest-docker 68.40% <88.88%> (+0.22%) ⬆️
funTest-non-docker 33.29% <ø> (ø)
test-ubuntu-24.04 39.27% <0.00%> (-0.07%) ⬇️
test-windows-2022 39.25% <0.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


private fun requestAllPackageDetails(projectModuleInfo: ModuleInfo) {
runBlocking {
withContext(Dispatchers.IO.limitedParallelism(20)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this special value ? Is it from empirical testing ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It aligns with other similar code that was introduced by @mnonnenmacher in 23c9bb0. But I agree that we should afterwards probably extract a constant.

@fviernau fviernau force-pushed the npm-view-concurrency branch from adc2520 to 2d457c9 Compare March 20, 2025 08:58
@fviernau fviernau requested review from sschuberth and nnobelis March 20, 2025 08:58

Verified

This commit was signed with the committer’s verified signature.
a-mccarthy Abigail McCarthy
Obtaining the package details via `npm info` is a performance
bottleneck of ORT's NPM package manager. Request the package details
for all packages upfront, in parallel to reduce execution time.
Experiments on a development machine show that execution of `NpmFunTest`
now takes `1 min 13 sec` instead of `3 min 47 sec`.

Fixes: #9950.

Signed-off-by: Frank Viernau <[email protected]>
@fviernau fviernau force-pushed the npm-view-concurrency branch from 2d457c9 to 30bfebe Compare March 20, 2025 09:08
val info = queue.removeFirst()

@Suppress("ComplexCondition")
if (!info.isProject && info.isInstalled && !info.name.isNullOrBlank() && !info.version.isNullOrBlank()) {
Copy link
Member

@sschuberth sschuberth Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity: Aren't isProject and isInstalled mutually exclusive? I.e. can a project ever get installed?

Copy link
Member Author

@fviernau fviernau Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isInstalled refers to whether there is a packageJson file existing under Path.

The !isProject can be interpreted as isPackage and combining this with isInstalled to me makes a lot of sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isInstalled refers to whether there is a packageJson file existing under Path.

For the record, here's what I did to confirm that statement for my own confidence. Drilling down, isInstalled is implemented as

private val ModuleInfo.isInstalled: Boolean get() = path != null

and path is documented as

The path to the directory where the package is *installed*.

(emphasis mine, as that's the part that confused me). Also, ModuleInfo is populated from output of npm list, which is documented as "This command will print to stdout all the versions of packages that are installed". So to me that sounded like we'll only get data in ModuleInfo (and the path property) for things that have been installed before via npm install.

But the root project itself seems to be an exception to that. Running npm list --json --long e.g. in plugins/package-managers/node/src/funTest/assets/projects/synthetic/pnpm/nested-project creates JSON output that does contain a path for the root project's package.json. However, it does not contain a path for sub/package.json.

}

private enum class Scope(val descriptor: String) {
DEPENDENCIES("dependencies"),
DEV_DEPENDENCIES("devDependencies")
}

private fun ModuleInfo.getAllPackageNodeModuleIds(): Set<String> {
val queue = Scope.entries.flatMapTo(LinkedList()) { getScopeDependencies(it) }
val result = mutableSetOf<String>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could use a surrounding buildSet {} (and function expression).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fviernau, are you ok if I address this in a small follow-up?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fviernau, are you ok if I address this in a small follow-up?

sure.

@fviernau fviernau merged commit 619221d into main Mar 21, 2025
38 of 40 checks passed
@fviernau fviernau deleted the npm-view-concurrency branch March 21, 2025 12:35
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.

Performance regression during "Analyze" of NPM projects after upgrading from v34.0.0 to v37.0.0
3 participants