perf: report download progress less often (#6906)

ref https://github.com/pnpm/pnpm/pull/6819
This commit is contained in:
Zoltan Kochan
2023-08-04 12:33:13 +03:00
committed by GitHub
parent 8a4dac63c3
commit 840b65bda6
4 changed files with 27 additions and 2 deletions

View File

@@ -0,0 +1,6 @@
---
"@pnpm/tarball-fetcher": patch
"pnpm": patch
---
Report download progress less often to improve performance.

View File

@@ -41,6 +41,7 @@
"@pnpm/graceful-fs": "workspace:*",
"@pnpm/prepare-package": "workspace:*",
"@zkochan/retry": "^0.2.0",
"lodash.throttle": "4.1.1",
"p-map-values": "^1.0.0",
"ramda": "npm:@pnpm/ramda@0.28.1",
"ssri": "10.0.4"
@@ -53,6 +54,7 @@
"@pnpm/tarball-fetcher": "workspace:*",
"@pnpm/test-fixtures": "workspace:*",
"@pnpm/types": "workspace:*",
"@types/lodash.throttle": "4.1.7",
"@types/ramda": "0.28.20",
"@types/retry": "^0.12.2",
"@types/ssri": "^7.1.1",

View File

@@ -5,6 +5,7 @@ import { type FetchResult } from '@pnpm/fetcher-base'
import type { Cafs, DeferredManifestPromise } from '@pnpm/cafs-types'
import { type FetchFromRegistry } from '@pnpm/fetching-types'
import * as retry from '@zkochan/retry'
import throttle from 'lodash.throttle'
import ssri from 'ssri'
import { BadTarballError } from './errorTypes'
@@ -153,8 +154,8 @@ export function createDownloader (
opts.onStart(size, currentAttempt)
}
// In order to reduce the amount of logs, we only report the download progress of big tarballs
const onProgress = size != null && size >= BIG_TARBALL_SIZE
? opts.onProgress
const onProgress = (size != null && size >= BIG_TARBALL_SIZE && opts.onProgress)
? throttle(opts.onProgress, 500)
: undefined
let downloaded = 0
res.body!.on('data', (chunk: Buffer) => {

16
pnpm-lock.yaml generated
View File

@@ -1582,6 +1582,9 @@ importers:
'@zkochan/retry':
specifier: ^0.2.0
version: 0.2.0
lodash.throttle:
specifier: 4.1.1
version: 4.1.1
p-map-values:
specifier: ^1.0.0
version: 1.0.0
@@ -1613,6 +1616,9 @@ importers:
'@pnpm/types':
specifier: workspace:*
version: link:../../packages/types
'@types/lodash.throttle':
specifier: 4.1.7
version: 4.1.7
'@types/ramda':
specifier: 0.28.20
version: 0.28.20
@@ -8505,6 +8511,12 @@ packages:
'@types/lodash': 4.14.196
dev: true
/@types/lodash.throttle@4.1.7:
resolution: {integrity: sha512-znwGDpjCHQ4FpLLx19w4OXDqq8+OvREa05H89obtSyXyOFKL3dDjCslsmfBz0T2FU8dmf5Wx1QvogbINiGIu9g==}
dependencies:
'@types/lodash': 4.14.196
dev: true
/@types/lodash@4.14.181:
resolution: {integrity: sha512-n3tyKthHJbkiWhDZs3DkhkCzt2MexYHXlX0td5iMplyfwketaOeKboEVBqzceH7juqvEg3q5oUoBFxSLu7zFag==}
@@ -13323,6 +13335,10 @@ packages:
resolution: {integrity: sha512-+WKqsK294HMSc2jEbNgpHpd0JfIBhp7rEV4aqXWqFr6AlXov+SlcgB1Fv01y2kGe3Gc8nMW7VA0SrGuSkRfIEg==}
dev: true
/lodash.throttle@4.1.1:
resolution: {integrity: sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==}
dev: false
/lodash.truncate@4.4.2:
resolution: {integrity: sha512-jttmRe7bRse52OsWIMDLaXxWqRAmtIUccAQ3garviCqJjafXOfNMO0yMfNpdD6zbGaTU0P5Nz7e7gAT6cKmJRw==}