-
Notifications
You must be signed in to change notification settings - Fork 39
fix(shared-metrics): reduce memory consumption with many dependencies #2088
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3925cc5
fix(shared-metrics): reduce memory consumption with many dependencies
kirrg001 7d27555
chore: tidy up
kirrg001 71a0fb6
chore: fix
kirrg001 98634fb
chore: moved comment to the rigth place
kirrg001 c318080
chore: updated comments
aryamohanan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/shared-metrics/test/dependencies/app-with-many-dependencies/app.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * (c) Copyright IBM Corp. 2025 | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| // NOTE: c8 bug https://github.com/bcoe/c8/issues/166 | ||
| process.on('SIGTERM', () => { | ||
| process.disconnect(); | ||
| process.exit(0); | ||
| }); | ||
|
|
||
| const instana = require('@instana/collector'); | ||
| instana(); | ||
|
|
||
| const express = require('express'); | ||
|
|
||
| const logPrefix = `Many dependencies app (${process.pid}):\t`; | ||
|
|
||
| const app = express(); | ||
|
|
||
| app.get('/', (req, res) => res.sendStatus(200)); | ||
|
|
||
| app.listen(process.env.APP_PORT, () => { | ||
| log(`Listening on port: ${process.env.APP_PORT}`); | ||
| }); | ||
|
|
||
| function log() { | ||
| const args = Array.prototype.slice.call(arguments); | ||
| args[0] = logPrefix + args[0]; | ||
| // eslint-disable-next-line no-console | ||
| console.log.apply(console, args); | ||
| } |
58 changes: 58 additions & 0 deletions
58
packages/shared-metrics/test/dependencies/app-with-many-dependencies/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| { | ||
| "name": "app-with-many-dependencies", | ||
| "version": "1.0.0", | ||
| "description": "", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "type": "commonjs", | ||
| "dependencies": { | ||
| "@angular/animations": "20.0.3", | ||
| "@angular/cdk": "20.0.3", | ||
| "@angular/common": "20.0.3", | ||
| "@angular/compiler": "20.0.3", | ||
| "@angular/core": "20.0.3", | ||
| "@angular/forms": "20.0.3", | ||
| "@angular/material": "20.0.3", | ||
| "@angular/material-moment-adapter": "20.0.3", | ||
| "@angular/platform-browser": "20.0.3", | ||
| "@angular/platform-browser-dynamic": "20.0.3", | ||
| "@angular/router": "20.0.3", | ||
| "@ng-matero/extensions": "20.0.3", | ||
| "angular13-organization-chart": "2.0.0", | ||
| "bcm-in-frontend-v2": "file:", | ||
| "bcm-ph-frontend": "file:", | ||
| "chart.js": "4.4.1", | ||
| "chartjs-plugin-zoom": "2.0.1", | ||
| "compression": "1.8.1", | ||
| "dayjs": "1.11.7", | ||
| "dotenv": "16.4.5", | ||
| "express": "4.21.2", | ||
| "file-saver": "2.0.5", | ||
| "flatpickr": "4.6.13", | ||
| "http-proxy": "1.18.1", | ||
| "ibmcloud-appid-js": "1.0.1", | ||
| "keen-slider": "6.8.6", | ||
| "leaflet": "1.9.3", | ||
| "lodash-es": "4.17.21", | ||
| "moment": "2.30.1", | ||
| "path-to-regexp": "0.1.12", | ||
| "rxjs": "7.8.1", | ||
| "tslib": "2.3.0", | ||
| "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz", | ||
| "zone.js": "0.15.1" | ||
| }, | ||
| "devDependencies": { | ||
| "@angular-devkit/build-angular": "20.0.2", | ||
| "@angular/cli": "19.2.15", | ||
| "@angular/compiler-cli": "20.0.3", | ||
| "@schematics/angular": "18.2.3", | ||
| "@types/leaflet": "1.9.0", | ||
| "@types/lodash-es": "4.17.7", | ||
| "typescript": "5.8.3" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -212,6 +212,53 @@ describe('dependencies', function () { | |
| }) | ||
| )); | ||
| }); | ||
|
|
||
| describe('with many dependencies', () => { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you comment out the fix in dependencies.js, the test will fail and not report any dependencies because it never ends. |
||
| const appDir = path.join(__dirname, 'app-with-many-dependencies'); | ||
|
|
||
| let controls; | ||
|
|
||
| before(async () => { | ||
| // eslint-disable-next-line no-console | ||
| console.log('Installing dependencies for app-with-many-dependencies. This may take a while...'); | ||
| runCommandSync('rm -rf node_modules', appDir); | ||
| runCommandSync('npm install --no-optional --no-audit --no-package-lock', appDir); | ||
| // eslint-disable-next-line no-console | ||
| console.log('Installed dependencies for app-with-many-dependencies'); | ||
| controls = new ProcessControls({ | ||
| dirname: appDir, | ||
| useGlobalAgent: true | ||
| }); | ||
|
|
||
| await controls.startAndWaitForAgentConnection(); | ||
| }); | ||
|
|
||
| before(async () => { | ||
| await agentControls.clearReceivedTraceData(); | ||
| }); | ||
|
|
||
| after(async () => { | ||
| await controls.stop(); | ||
| }); | ||
|
|
||
| it('should limit dependencies', () => { | ||
| return retry(async () => { | ||
| const allMetrics = await agentControls.getAllMetrics(controls.getPid()); | ||
| expect(allMetrics).to.be.an('array'); | ||
|
|
||
| const deps = findMetric(allMetrics, ['dependencies']); | ||
| expect(deps).to.be.an('object'); | ||
| expect(Object.keys(deps).length).to.be.at.least(500); | ||
| expect(Object.keys(deps).length).to.be.at.most(1000); | ||
|
|
||
| // expect that the first dependency is in the list | ||
| expect(deps['@ampproject/remapping']).to.exist; | ||
|
|
||
| // expect that the last dependency is in the list | ||
| expect(deps['zone.js']).to.exist; | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| /** | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.