@jsenv/performance-impact 4.2.1 → 4.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/performance-impact",
3
- "version": "4.2.1",
3
+ "version": "4.3.1",
4
4
  "description": "Report pull request impacts on performance metrics",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -36,9 +36,9 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@jsenv/dynamic-import-worker": "1.2.1",
39
- "@jsenv/filesystem": "4.6.6",
40
- "@jsenv/github-pull-request-impact": "1.7.5",
41
- "@jsenv/humanize": "1.1.0",
39
+ "@jsenv/filesystem": "4.10.2",
40
+ "@jsenv/github-pull-request-impact": "1.7.7",
41
+ "@jsenv/humanize": "1.2.8",
42
42
  "@jsenv/log": "3.5.2"
43
43
  }
44
44
  }
package/readme.md CHANGED
@@ -24,7 +24,7 @@ With time you'll be capable to recognize unusual variation in your performance m
24
24
 
25
25
  ## How to catch small performance impacts?
26
26
 
27
- Catching (very) small performance impacts with confidence requires repetition and time. You need to:
27
+ Catching (very) small performance impacts with confidence requires repetition and time. You need to:
28
28
 
29
29
  1. Let your code be used a lot of times in a lot of scenarios and see the results. This could be scripts, real users or both.
30
30
 
@@ -29,7 +29,7 @@ export const formatImpactAsPercentage = ({
29
29
  metricValueBeforeMerge === 0
30
30
  ? 1
31
31
  : metricValueAfterMerge === 0
32
- ? -1
33
- : diff / metricValueBeforeMerge;
32
+ ? -1
33
+ : diff / metricValueBeforeMerge;
34
34
  return formatRatioAsPercentage(diffRatio);
35
35
  };
@@ -52,10 +52,10 @@ const getAllImpactRatios = ({ afterMergeMetrics, beforeMergeMetrics }) => {
52
52
  metricDiff === 0
53
53
  ? 0
54
54
  : metricValueBeforeMerge === 0
55
- ? 1
56
- : metricValueAfterMerge === 0
57
- ? -1
58
- : metricDiff / metricValueBeforeMerge;
55
+ ? 1
56
+ : metricValueAfterMerge === 0
57
+ ? -1
58
+ : metricDiff / metricValueBeforeMerge;
59
59
  allRatios.push(metricDiffRatio);
60
60
  });
61
61
  return allRatios;
@@ -29,13 +29,52 @@ export const startMeasures = ({
29
29
  });
30
30
  }
31
31
  if (filesystem) {
32
+ const _internalFs = process.binding("fs");
33
+ const restoreCallbackSet = new Set();
34
+ let fsOpenCall = 0;
35
+ let fsStatCall = 0;
36
+ const methodEffects = {
37
+ open: () => {
38
+ fsOpenCall++;
39
+ },
40
+ openFileHandle: () => {
41
+ fsOpenCall++;
42
+ },
43
+ stat: () => {
44
+ fsStatCall++;
45
+ },
46
+ lstat: () => {
47
+ fsStatCall++;
48
+ },
49
+ access: () => {
50
+ fsStatCall++;
51
+ },
52
+ };
53
+ for (const method of Object.keys(methodEffects)) {
54
+ const previous = _internalFs[method];
55
+ if (typeof previous !== "function") {
56
+ continue;
57
+ }
58
+ _internalFs[method] = function (...args) {
59
+ methodEffects[method](...args);
60
+ return previous.call(this, ...args);
61
+ };
62
+ restoreCallbackSet.add(() => {
63
+ _internalFs[method] = previous;
64
+ });
65
+ }
32
66
  const beforeRessourceUsage = resourceUsage();
33
67
  measures.push(() => {
68
+ for (const restoreCallback of restoreCallbackSet) {
69
+ restoreCallback();
70
+ }
34
71
  const afterRessourceUsage = resourceUsage();
35
72
  const fsRead = afterRessourceUsage.fsRead - beforeRessourceUsage.fsRead;
36
73
  const fsWrite =
37
74
  afterRessourceUsage.fsWrite - beforeRessourceUsage.fsWrite;
38
75
  return {
76
+ fsOpenCall,
77
+ fsStatCall,
39
78
  fsRead,
40
79
  fsWrite,
41
80
  };