@eagleoutice/flowr 2.13.13 → 2.13.14

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.
Files changed (61) hide show
  1. package/README.md +29 -26
  2. package/benchmark/calibration.d.ts +18 -0
  3. package/benchmark/calibration.js +63 -0
  4. package/benchmark/slicer.d.ts +19 -0
  5. package/benchmark/slicer.js +84 -1
  6. package/benchmark/stats/feature-counts.d.ts +6 -0
  7. package/benchmark/stats/feature-counts.js +61 -0
  8. package/benchmark/stats/print.js +20 -0
  9. package/benchmark/stats/sigdb-counts.d.ts +7 -0
  10. package/benchmark/stats/sigdb-counts.js +219 -0
  11. package/benchmark/stats/size-of.d.ts +6 -0
  12. package/benchmark/stats/size-of.js +8 -0
  13. package/benchmark/stats/stats.d.ts +79 -0
  14. package/benchmark/stats/stats.js +7 -1
  15. package/benchmark/stopwatch.d.ts +4 -0
  16. package/benchmark/stopwatch.js +12 -1
  17. package/benchmark/summarizer/data.d.ts +17 -1
  18. package/benchmark/summarizer/first-phase/input.js +5 -0
  19. package/benchmark/summarizer/first-phase/process.js +12 -2
  20. package/benchmark/summarizer/second-phase/graph.d.ts +1 -1
  21. package/benchmark/summarizer/second-phase/graph.js +214 -16
  22. package/benchmark/summarizer/second-phase/process.js +56 -0
  23. package/benchmark/summarizer/summarizer.js +1 -2
  24. package/cli/benchmark-app.d.ts +1 -0
  25. package/cli/benchmark-app.js +2 -1
  26. package/cli/benchmark-helper-app.d.ts +1 -0
  27. package/cli/benchmark-helper-app.js +12 -2
  28. package/cli/common/options.d.ts +10 -0
  29. package/cli/common/options.js +3 -1
  30. package/cli/common/scripts-info.d.ts +10 -0
  31. package/control-flow/cfg-builder.d.ts +30 -0
  32. package/control-flow/cfg-builder.js +79 -0
  33. package/control-flow/extract-cfg.js +17 -10
  34. package/dataflow/environments/apply-kill.d.ts +3 -3
  35. package/dataflow/environments/apply-kill.js +60 -31
  36. package/dataflow/environments/reference-to-maybe.d.ts +5 -3
  37. package/dataflow/environments/reference-to-maybe.js +17 -52
  38. package/dataflow/environments/resolve-helper.d.ts +2 -1
  39. package/dataflow/environments/resolve-helper.js +2 -1
  40. package/dataflow/graph/df-helper.d.ts +2 -1
  41. package/dataflow/info.d.ts +7 -1
  42. package/dataflow/info.js +36 -7
  43. package/dataflow/internal/process/functions/call/built-in/built-in-expression-list.js +33 -10
  44. package/dataflow/internal/process/functions/call/built-in/built-in-for-loop.js +4 -1
  45. package/dataflow/internal/process/functions/call/built-in/built-in-local.js +6 -2
  46. package/dataflow/internal/process/functions/call/built-in/built-in-repeat-loop.js +2 -1
  47. package/dataflow/internal/process/functions/call/built-in/built-in-replacement.js +7 -2
  48. package/dataflow/internal/process/functions/call/built-in/built-in-try-catch.js +8 -1
  49. package/documentation/doc-readme.js +5 -2
  50. package/documentation/doc-util/doc-issue.d.ts +2 -0
  51. package/documentation/doc-util/doc-issue.js +3 -1
  52. package/documentation/wiki-dataflow-graph.js +4 -0
  53. package/documentation/wiki-faq.js +6 -2
  54. package/documentation/wiki-onboarding.js +11 -1
  55. package/documentation/wiki-setup.js +2 -1
  56. package/package.json +9 -4
  57. package/r-bridge/lang-4.x/tree-sitter/tree-sitter-normalize.js +11 -9
  58. package/slicing/static/slice-call.js +4 -4
  59. package/util/node-version.d.ts +4 -0
  60. package/util/node-version.js +29 -0
  61. package/util/version.js +1 -1
@@ -6,27 +6,137 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.writeGraphOutput = writeGraphOutput;
7
7
  const fs_1 = __importDefault(require("fs"));
8
8
  const json_1 = require("../../../util/json");
9
+ const feature_counts_1 = require("../../stats/feature-counts");
10
+ const sigdb_counts_1 = require("../../stats/sigdb-counts");
11
+ /** ns to ms */
12
+ function ms(nanoseconds) {
13
+ return nanoseconds / 1e6;
14
+ }
15
+ /**
16
+ * The median is a lot less sensitive to the load of the machine that produced the measurement than the mean,
17
+ * hence we plot the median whenever there is one and only report the mean as additional information.
18
+ */
19
+ function plotValue(measurement) {
20
+ return Number.isFinite(measurement.median) ? measurement.median : measurement.mean;
21
+ }
22
+ function timeEntry(name, measurement) {
23
+ if (!measurement?.mean || !measurement?.std) {
24
+ return undefined;
25
+ }
26
+ return {
27
+ name,
28
+ unit: 'ms',
29
+ value: ms(plotValue(measurement)),
30
+ range: String(ms(measurement.std)),
31
+ extra: `mean: ${ms(measurement.mean).toFixed(2)}ms`
32
+ };
33
+ }
34
+ const SigDbPrefix = 'signature database';
35
+ /** bytes to KiB */
36
+ function kib(bytes) {
37
+ return bytes / 1024;
38
+ }
39
+ /**
40
+ * What the signature database of the benchmarked release carries. It describes the machine, not a single
41
+ * measurement, so it is counted here, once, after every measured phase, and a machine without a mounted
42
+ * database simply contributes nothing.
43
+ */
44
+ function signatureDatabaseEntries(counts) {
45
+ if (counts === undefined) {
46
+ return [];
47
+ }
48
+ const data = [];
49
+ const count = (name, value) => {
50
+ if (typeof value === 'number') {
51
+ data.push({ name: `${SigDbPrefix} ${name}`, unit: '#', value });
52
+ }
53
+ };
54
+ const bytes = (name, value) => {
55
+ if (typeof value === 'number') {
56
+ data.push({ name: `${SigDbPrefix} ${name}`, unit: 'KiB', value: kib(value) });
57
+ }
58
+ };
59
+ count('bundles', counts.bundles);
60
+ for (const [kind, value] of Object.entries(counts.bundlesByKind ?? {})) {
61
+ count(`bundles (${kind})`, value);
62
+ }
63
+ count('packages', counts.packages);
64
+ count('package versions', counts.packageVersions);
65
+ count('functions', counts.functions);
66
+ for (const [kind, value] of Object.entries(counts.functionsByKind ?? {})) {
67
+ count(`functions (${kind})`, value);
68
+ }
69
+ count('base functions', counts.base?.functions);
70
+ count('base parameters', counts.base?.parameters);
71
+ for (const [carries, value] of Object.entries(counts.base?.functionsCarrying ?? {})) {
72
+ count(`base functions (${carries})`, value);
73
+ }
74
+ bytes('size', counts.size);
75
+ for (const [kind, value] of Object.entries(counts.sizeByKind ?? {})) {
76
+ bytes(`size (${kind})`, value);
77
+ }
78
+ bytes('size (dictionaries)', counts.sizeOfDictionaries);
79
+ bytes('size (manifests)', counts.sizeOfManifests);
80
+ return data;
81
+ }
9
82
  /**
10
83
  * Write the graph output for the ultimate slicer stats to a file
11
84
  * @param ultimate - The ultimate slicer stats
12
85
  * @param outputGraphPath - The path to write the graph output to
13
86
  */
14
- function writeGraphOutput(ultimate, outputGraphPath) {
87
+ async function writeGraphOutput(ultimate, outputGraphPath) {
15
88
  console.log(`Producing benchmark graph data (${outputGraphPath})...`);
16
89
  const data = [];
17
- for (const { name, measurements } of [{ name: 'per-file', measurements: ultimate.commonMeasurements }, { name: 'per-slice', measurements: ultimate.perSliceMeasurements }]) {
90
+ for (const { name, measurements } of [
91
+ { name: 'per-file', measurements: ultimate.commonMeasurements },
92
+ { name: 'per-slice', measurements: ultimate.perSliceMeasurements },
93
+ { name: 'additional', measurements: ultimate.additionalMeasurements ?? new Map() }
94
+ ]) {
18
95
  for (const [point, measurement] of measurements) {
19
- if (point === 'close R session' || point === 'initialize R session' || !measurement?.mean || !measurement?.std) {
96
+ if (point === 'close R session' || point === 'initialize R session') {
20
97
  continue;
21
98
  }
22
99
  const pointName = point === 'total' ? `total ${name}` : point;
23
- data.push({
24
- name: pointName[0].toUpperCase() + pointName.slice(1),
25
- unit: 'ms',
26
- value: Number(measurement.mean / 1e6),
27
- range: String(Number(measurement.std / 1e6)),
28
- extra: `median: ${(measurement.median / 1e6).toFixed(2)}ms`
29
- });
100
+ const entry = timeEntry(pointName[0].toUpperCase() + pointName.slice(1), measurement);
101
+ if (entry) {
102
+ data.push(entry);
103
+ }
104
+ }
105
+ }
106
+ // the per 100 lines of input pendants to the per-token measurements, less sensitive to the file size mix
107
+ for (const { name, measurement } of [
108
+ { name: 'Retrieve AST per 100 lines', measurement: ultimate.retrieveTimePer100Lines },
109
+ { name: 'Normalize AST per 100 lines', measurement: ultimate.normalizeTimePer100Lines },
110
+ { name: 'Dataflow per 100 lines', measurement: ultimate.dataflowTimePer100Lines },
111
+ { name: 'Control flow per 100 lines', measurement: ultimate.controlFlowTimePer100Lines },
112
+ { name: 'Static slicing per 100 lines', measurement: ultimate.sliceTimePer100Lines },
113
+ { name: 'Reconstruct code per 100 lines', measurement: ultimate.reconstructTimePer100Lines },
114
+ { name: 'Total common per 100 lines', measurement: ultimate.totalCommonTimePer100Lines },
115
+ { name: 'Total per-slice per 100 lines', measurement: ultimate.totalPerSliceTimePer100Lines }
116
+ ]) {
117
+ const entry = timeEntry(name, measurement);
118
+ if (entry) {
119
+ data.push(entry);
120
+ }
121
+ }
122
+ // what the analyzed version of flowR itself carries, so a release also shows how the feature set grew.
123
+ // It describes the version, not the suite, so it is counted here, once, instead of in every benchmarked file.
124
+ const features = (0, feature_counts_1.countFeatures)();
125
+ for (const [name, value] of [
126
+ ['linting rules', features.lintingRules],
127
+ ['queries', features.queries],
128
+ ['built-in definitions', features.builtinDefinitions],
129
+ ['built-in definitions (default handler)', features.builtinDefinitionsDefault],
130
+ ['built-in definitions (own handler)', features.builtinDefinitionsCustom],
131
+ ['built-in definitions (with eval handler)', features.builtinDefinitionsWithEvalHandler]
132
+ ]) {
133
+ if (typeof value === 'number') {
134
+ data.push({ name, unit: '#', value });
135
+ }
136
+ }
137
+ for (const [tag, value] of Object.entries(features.lintingRulesByTag)) {
138
+ if (typeof value === 'number') {
139
+ data.push({ name: `linting rules (${tag})`, unit: '#', value });
30
140
  }
31
141
  }
32
142
  data.push({
@@ -34,6 +144,67 @@ function writeGraphOutput(ultimate, outputGraphPath) {
34
144
  unit: '#',
35
145
  value: ultimate.totalRequests
36
146
  });
147
+ data.push({
148
+ name: 'number of slices',
149
+ unit: '#',
150
+ value: ultimate.totalSlices
151
+ });
152
+ // what the analysis works on and produces, so a change in runtime can be related to a change in size
153
+ for (const [name, measurement] of [
154
+ ['input lines', ultimate.input.numberOfLines],
155
+ ['input tokens (normalized)', ultimate.input.numberOfNormalizedTokens],
156
+ ['dataflow vertices', ultimate.dataflow.numberOfNodes],
157
+ ['dataflow edges', ultimate.dataflow.numberOfEdges],
158
+ ['dataflow calls', ultimate.dataflow.numberOfCalls],
159
+ ['dataflow function definitions', ultimate.dataflow.numberOfFunctionDefinitions],
160
+ ['control flow vertices', ultimate.controlFlow?.numberOfVertices],
161
+ ['control flow edges', ultimate.controlFlow?.numberOfEdges]
162
+ ]) {
163
+ if (measurement) {
164
+ data.push({
165
+ name,
166
+ unit: '#',
167
+ value: plotValue(measurement),
168
+ range: String(measurement.std),
169
+ extra: `mean: ${measurement.mean.toFixed(2)}`
170
+ });
171
+ }
172
+ }
173
+ // what the data frame shape inference sees and how precise it is, so a change in its precision becomes visible
174
+ const shapes = ultimate.dataFrameShape;
175
+ if (shapes) {
176
+ const files = shapes.numberOfDataFrameFiles + shapes.numberOfNonDataFrameFiles;
177
+ data.push({
178
+ name: 'files with data frames',
179
+ unit: '#',
180
+ value: shapes.numberOfDataFrameFiles,
181
+ extra: `out of ${files} files`
182
+ });
183
+ // only a few files of a suite use data frames at all, so the median over all files would be zero
184
+ for (const [name, measurement] of [
185
+ ['data frame operations', shapes.numberOfOperations],
186
+ ['data frame operation nodes', shapes.numberOfOperationNodes],
187
+ ['data frame value nodes', shapes.numberOfValueNodes],
188
+ ['data frame constraints', shapes.numberOfTotalConstraints],
189
+ ['data frame shapes (exact)', shapes.numberOfTotalExact],
190
+ ['data frame shapes (bottom)', shapes.numberOfTotalBottom],
191
+ ['data frame shapes (top)', shapes.numberOfTotalTop]
192
+ ]) {
193
+ data.push({
194
+ name,
195
+ unit: '#',
196
+ value: measurement.total,
197
+ extra: `mean: ${measurement.mean.toFixed(2)} per file`
198
+ });
199
+ }
200
+ data.push({
201
+ name: 'memory (df-shapes)',
202
+ unit: 'KiB',
203
+ value: plotValue(shapes.sizeOfInfo) / 1024,
204
+ range: String(shapes.sizeOfInfo.std / 1024),
205
+ extra: `mean: ${(shapes.sizeOfInfo.mean / 1024).toFixed(2)}`
206
+ });
207
+ }
37
208
  data.push({
38
209
  name: 'failed to reconstruct/re-parse',
39
210
  unit: '#',
@@ -45,25 +216,52 @@ function writeGraphOutput(ultimate, outputGraphPath) {
45
216
  unit: '#',
46
217
  value: ultimate.timesHitThreshold
47
218
  });
219
+ // the reduction without comments and empty lines tells a different story than the raw one
220
+ for (const [name, measurement] of [
221
+ ['reduction (lines)', ultimate.reduction.numberOfLines],
222
+ ['reduction (dataflow vertices)', ultimate.reduction.numberOfDataflowNodes],
223
+ ['reduction no fluff (characters)', ultimate.reductionNoFluff.numberOfCharacters],
224
+ ['reduction no fluff (normalized tokens)', ultimate.reductionNoFluff.numberOfNormalizedTokens]
225
+ ]) {
226
+ if (measurement) {
227
+ data.push({
228
+ name,
229
+ unit: '#',
230
+ value: plotValue(measurement),
231
+ extra: `mean: ${measurement.mean.toFixed(4)}, std: ${measurement.std.toFixed(4)}`
232
+ });
233
+ }
234
+ }
48
235
  data.push({
49
236
  name: 'reduction (characters)',
50
237
  unit: '#',
51
- value: ultimate.reduction.numberOfCharacters.mean,
52
- extra: `std: ${ultimate.reduction.numberOfCharacters.std}`
238
+ value: plotValue(ultimate.reduction.numberOfCharacters),
239
+ extra: `mean: ${ultimate.reduction.numberOfCharacters.mean.toFixed(4)}, std: ${ultimate.reduction.numberOfCharacters.std.toFixed(4)}`
53
240
  });
54
241
  data.push({
55
242
  name: 'reduction (normalized tokens)',
56
243
  unit: '#',
57
- value: ultimate.reduction.numberOfNormalizedTokens.mean,
58
- extra: `std: ${ultimate.reduction.numberOfNormalizedTokens.std}`
244
+ value: plotValue(ultimate.reduction.numberOfNormalizedTokens),
245
+ extra: `mean: ${ultimate.reduction.numberOfNormalizedTokens.mean.toFixed(4)}, std: ${ultimate.reduction.numberOfNormalizedTokens.std.toFixed(4)}`
59
246
  });
247
+ if (ultimate.controlFlow) {
248
+ data.push({
249
+ name: 'memory (cfg-graph)',
250
+ unit: 'KiB',
251
+ value: plotValue(ultimate.controlFlow.sizeOfObject) / 1024,
252
+ range: String(ultimate.controlFlow.sizeOfObject.std / 1024),
253
+ extra: `mean: ${(ultimate.controlFlow.sizeOfObject.mean / 1024).toFixed(2)}`
254
+ });
255
+ }
60
256
  data.push({
61
257
  name: 'memory (df-graph)',
62
258
  unit: 'KiB',
63
- value: ultimate.dataflow.sizeOfObject.mean / 1024,
259
+ value: plotValue(ultimate.dataflow.sizeOfObject) / 1024,
64
260
  range: String(ultimate.dataflow.sizeOfObject.std / 1024),
65
- extra: `median: ${(ultimate.dataflow.sizeOfObject.median / 1024).toFixed(2)}`
261
+ extra: `mean: ${(ultimate.dataflow.sizeOfObject.mean / 1024).toFixed(2)}`
66
262
  });
263
+ // the database is a property of the release, not of a file, so it is counted once and comes last
264
+ data.push(...signatureDatabaseEntries(await (0, sigdb_counts_1.countSignatureDatabase)()));
67
265
  // write the output file
68
266
  fs_1.default.writeFileSync(outputGraphPath, JSON.stringify(data, json_1.jsonReplacer));
69
267
  }
@@ -17,6 +17,15 @@ const arrays_1 = require("../../../util/collections/arrays");
17
17
  function summarizeAllSummarizedStats(stats) {
18
18
  const commonMeasurements = new defaultmap_1.DefaultMap(() => []);
19
19
  const perSliceMeasurements = new defaultmap_1.DefaultMap(() => []);
20
+ const additionalMeasurements = new defaultmap_1.DefaultMap(() => []);
21
+ const retrieveTimesPer100Lines = [];
22
+ const normalizeTimesPer100Lines = [];
23
+ const dataflowTimesPer100Lines = [];
24
+ const totalCommonTimesPer100Lines = [];
25
+ const controlFlowTimesPer100Lines = [];
26
+ const sliceTimesPer100Lines = [];
27
+ const reconstructTimesPer100Lines = [];
28
+ const totalPerSliceTimesPer100Lines = [];
20
29
  const sliceTimesPerToken = [];
21
30
  const reconstructTimesPerToken = [];
22
31
  const totalPerSliceTimesPerToken = [];
@@ -43,6 +52,19 @@ function summarizeAllSummarizedStats(stats) {
43
52
  for (const [k, v] of stat.perSliceMeasurements.measurements) {
44
53
  perSliceMeasurements.get(k).push(v);
45
54
  }
55
+ for (const [k, v] of stat.additionalMeasurements ?? []) {
56
+ additionalMeasurements.get(k).push(Number(v));
57
+ }
58
+ retrieveTimesPer100Lines.push(stat.retrieveTimePer100Lines);
59
+ normalizeTimesPer100Lines.push(stat.normalizeTimePer100Lines);
60
+ dataflowTimesPer100Lines.push(stat.dataflowTimePer100Lines);
61
+ totalCommonTimesPer100Lines.push(stat.totalCommonTimePer100Lines);
62
+ if (stat.controlFlowTimePer100Lines !== undefined) {
63
+ controlFlowTimesPer100Lines.push(stat.controlFlowTimePer100Lines);
64
+ }
65
+ sliceTimesPer100Lines.push(stat.perSliceMeasurements.sliceTimePer100Lines);
66
+ reconstructTimesPer100Lines.push(stat.perSliceMeasurements.reconstructTimePer100Lines);
67
+ totalPerSliceTimesPer100Lines.push(stat.perSliceMeasurements.totalPerSliceTimePer100Lines);
46
68
  sliceTimesPerToken.push(stat.perSliceMeasurements.sliceTimePerToken);
47
69
  reconstructTimesPerToken.push(stat.perSliceMeasurements.reconstructTimePerToken);
48
70
  totalPerSliceTimesPerToken.push(stat.perSliceMeasurements.totalPerSliceTimePerToken);
@@ -78,6 +100,7 @@ function summarizeAllSummarizedStats(stats) {
78
100
  totalSlices: totalSlices,
79
101
  commonMeasurements: new Map([...commonMeasurements.entries()].map(([k, v]) => [k, (0, summarizer_1.summarizeMeasurement)(v)])),
80
102
  perSliceMeasurements: new Map([...perSliceMeasurements.entries()].map(([k, v]) => [k, (0, process_1.summarizeSummarizedMeasurement)(v)])),
103
+ additionalMeasurements: new Map([...additionalMeasurements.entries()].map(([k, v]) => [k, (0, summarizer_1.summarizeMeasurement)(v)])),
81
104
  sliceTimePerToken: (0, process_1.summarizeSummarizedTimePerToken)(sliceTimesPerToken),
82
105
  reconstructTimePerToken: (0, process_1.summarizeSummarizedTimePerToken)(reconstructTimesPerToken),
83
106
  totalPerSliceTimePerToken: (0, process_1.summarizeSummarizedTimePerToken)(totalPerSliceTimesPerToken),
@@ -88,6 +111,14 @@ function summarizeAllSummarizedStats(stats) {
88
111
  controlFlowTimePerToken: controlFlowTimePerToken.length > 0 ? (0, process_1.summarizeTimePerToken)(controlFlowTimePerToken) : undefined,
89
112
  callGraphTimePerToken: callGraphTimePerToken.length > 0 ? (0, process_1.summarizeTimePerToken)(callGraphTimePerToken) : undefined,
90
113
  dataFrameShapeTimePerToken: dataFrameShapeTimePerToken.length > 0 ? (0, process_1.summarizeTimePerToken)(dataFrameShapeTimePerToken) : undefined,
114
+ retrieveTimePer100Lines: (0, summarizer_1.summarizeMeasurement)(retrieveTimesPer100Lines),
115
+ normalizeTimePer100Lines: (0, summarizer_1.summarizeMeasurement)(normalizeTimesPer100Lines),
116
+ dataflowTimePer100Lines: (0, summarizer_1.summarizeMeasurement)(dataflowTimesPer100Lines),
117
+ totalCommonTimePer100Lines: (0, summarizer_1.summarizeMeasurement)(totalCommonTimesPer100Lines),
118
+ controlFlowTimePer100Lines: controlFlowTimesPer100Lines.length > 0 ? (0, summarizer_1.summarizeMeasurement)(controlFlowTimesPer100Lines) : undefined,
119
+ sliceTimePer100Lines: (0, process_1.summarizeSummarizedMeasurement)(sliceTimesPer100Lines),
120
+ reconstructTimePer100Lines: (0, process_1.summarizeSummarizedMeasurement)(reconstructTimesPer100Lines),
121
+ totalPerSliceTimePer100Lines: (0, process_1.summarizeSummarizedMeasurement)(totalPerSliceTimesPer100Lines),
91
122
  failedToRepParse,
92
123
  timesHitThreshold,
93
124
  reduction: (0, process_1.summarizeSummarizedReductions)(reductions),
@@ -111,6 +142,11 @@ function summarizeAllSummarizedStats(stats) {
111
142
  numberOfEdges: (0, summarizer_1.summarizeMeasurement)(dataflows.map(d => d.numberOfEdges)),
112
143
  sizeOfObject: (0, summarizer_1.summarizeMeasurement)(dataflows.map(d => d.sizeOfObject)),
113
144
  },
145
+ controlFlow: stats.some(s => s.controlFlow !== undefined) ? {
146
+ numberOfVertices: (0, summarizer_1.summarizeMeasurement)(stats.map(s => s.controlFlow?.numberOfVertices).filter(assert_1.isNotUndefined)),
147
+ numberOfEdges: (0, summarizer_1.summarizeMeasurement)(stats.map(s => s.controlFlow?.numberOfEdges).filter(assert_1.isNotUndefined)),
148
+ sizeOfObject: (0, summarizer_1.summarizeMeasurement)(stats.map(s => s.controlFlow?.sizeOfObject).filter(assert_1.isNotUndefined))
149
+ } : undefined,
114
150
  dataFrameShape: stats.some(s => s.dataFrameShape !== undefined) ? {
115
151
  numberOfDataFrameFiles: (0, arrays_1.arraySum)(stats.map(s => s.dataFrameShape?.numberOfDataFrameFiles).filter(assert_1.isNotUndefined)),
116
152
  numberOfNonDataFrameFiles: (0, arrays_1.arraySum)(stats.map(s => s.dataFrameShape?.numberOfNonDataFrameFiles).filter(assert_1.isNotUndefined)),
@@ -167,6 +203,7 @@ function summarizeAllUltimateStats(stats) {
167
203
  // average out / summarize other measurements
168
204
  commonMeasurements: new Map(stats_1.CommonSlicerMeasurements.filter(m => stats.some(s => s.commonMeasurements.has(m))).map(m => [m, (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.commonMeasurements.get(m)))])),
169
205
  perSliceMeasurements: new Map(stats_1.PerSliceMeasurements.map(m => [m, (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.perSliceMeasurements.get(m)))])),
206
+ additionalMeasurements: new Map(stats_1.AdditionalSlicerMeasurements.filter(m => stats.some(s => s.additionalMeasurements?.has(m))).map(m => [m, (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.additionalMeasurements?.get(m)).filter(assert_1.isNotUndefined))])),
170
207
  sliceTimePerToken: (0, process_1.summarizeSummarizedTimePerToken)(stats.map(s => s.sliceTimePerToken)),
171
208
  reconstructTimePerToken: (0, process_1.summarizeSummarizedTimePerToken)(stats.map(s => s.reconstructTimePerToken)),
172
209
  totalPerSliceTimePerToken: (0, process_1.summarizeSummarizedTimePerToken)(stats.map(s => s.totalPerSliceTimePerToken)),
@@ -176,6 +213,14 @@ function summarizeAllUltimateStats(stats) {
176
213
  totalCommonTimePerToken: (0, process_1.summarizeSummarizedTimePerToken)(stats.map(s => s.totalCommonTimePerToken)),
177
214
  controlFlowTimePerToken: stats.some(s => s.controlFlowTimePerToken !== undefined) ? (0, process_1.summarizeSummarizedTimePerToken)(stats.map(s => s.controlFlowTimePerToken).filter(assert_1.isNotUndefined)) : undefined,
178
215
  dataFrameShapeTimePerToken: stats.some(s => s.dataFrameShapeTimePerToken !== undefined) ? (0, process_1.summarizeSummarizedTimePerToken)(stats.map(s => s.dataFrameShapeTimePerToken).filter(assert_1.isNotUndefined)) : undefined,
216
+ retrieveTimePer100Lines: (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.retrieveTimePer100Lines).filter(assert_1.isNotUndefined)),
217
+ normalizeTimePer100Lines: (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.normalizeTimePer100Lines).filter(assert_1.isNotUndefined)),
218
+ dataflowTimePer100Lines: (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.dataflowTimePer100Lines).filter(assert_1.isNotUndefined)),
219
+ totalCommonTimePer100Lines: (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.totalCommonTimePer100Lines).filter(assert_1.isNotUndefined)),
220
+ controlFlowTimePer100Lines: stats.some(s => s.controlFlowTimePer100Lines !== undefined) ? (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.controlFlowTimePer100Lines).filter(assert_1.isNotUndefined)) : undefined,
221
+ sliceTimePer100Lines: (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.sliceTimePer100Lines).filter(assert_1.isNotUndefined)),
222
+ reconstructTimePer100Lines: (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.reconstructTimePer100Lines).filter(assert_1.isNotUndefined)),
223
+ totalPerSliceTimePer100Lines: (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.totalPerSliceTimePer100Lines).filter(assert_1.isNotUndefined)),
179
224
  reduction: (0, process_1.summarizeSummarizedReductions)(stats.map(s => s.reduction)),
180
225
  reductionNoFluff: (0, process_1.summarizeSummarizedReductions)(stats.map(s => s.reductionNoFluff)),
181
226
  input: {
@@ -197,6 +242,11 @@ function summarizeAllUltimateStats(stats) {
197
242
  numberOfEdges: (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.dataflow.numberOfEdges)),
198
243
  sizeOfObject: (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.dataflow.sizeOfObject)),
199
244
  },
245
+ controlFlow: stats.some(s => s.controlFlow !== undefined) ? {
246
+ numberOfVertices: (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.controlFlow?.numberOfVertices).filter(assert_1.isNotUndefined)),
247
+ numberOfEdges: (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.controlFlow?.numberOfEdges).filter(assert_1.isNotUndefined)),
248
+ sizeOfObject: (0, process_1.summarizeSummarizedMeasurement)(stats.map(s => s.controlFlow?.sizeOfObject).filter(assert_1.isNotUndefined))
249
+ } : undefined,
200
250
  dataFrameShape: stats.some(s => s.dataFrameShape !== undefined) ? {
201
251
  numberOfDataFrameFiles: (0, arrays_1.arraySum)(stats.map(s => s.dataFrameShape?.numberOfDataFrameFiles).filter(assert_1.isNotUndefined)),
202
252
  numberOfNonDataFrameFiles: (0, arrays_1.arraySum)(stats.map(s => s.dataFrameShape?.numberOfNonDataFrameFiles).filter(assert_1.isNotUndefined)),
@@ -256,6 +306,11 @@ function processNextSummary(line, allSummarized) {
256
306
  (0, assert_1.guard)(v.endsWith('n'), 'Expected a bigint');
257
307
  return [k, BigInt(v.slice(0, -1))];
258
308
  })),
309
+ additionalMeasurements: new Map((got.summarize.additionalMeasurements ?? [])
310
+ .map(([k, v]) => {
311
+ (0, assert_1.guard)(v.endsWith('n'), 'Expected a bigint');
312
+ return [k, BigInt(v.slice(0, -1))];
313
+ })),
259
314
  perSliceMeasurements: {
260
315
  ...got.summarize.perSliceMeasurements,
261
316
  // restore maps
@@ -279,6 +334,7 @@ function processNextUltimateSummary(line, allSummarized) {
279
334
  // restore maps
280
335
  commonMeasurements: new Map(got.commonMeasurements),
281
336
  perSliceMeasurements: new Map(got.perSliceMeasurements),
337
+ additionalMeasurements: new Map(got.additionalMeasurements ?? []),
282
338
  dataFrameShape: got.dataFrameShape !== undefined ? {
283
339
  ...got.dataFrameShape,
284
340
  perOperationNumber: new Map(got.dataFrameShape.perOperationNumber)
@@ -44,7 +44,6 @@ class BenchmarkSummarizer extends summarizer_1.Summarizer {
44
44
  }
45
45
  this.log('Done summarizing');
46
46
  }
47
- // eslint-disable-next-line @typescript-eslint/require-await -- just to obey the structure
48
47
  async summarizePhase() {
49
48
  this.log(`Summarizing all summaries from ${this.summaryFile()}...`);
50
49
  this.removeIfExists(this.config.outputPath);
@@ -55,7 +54,7 @@ class BenchmarkSummarizer extends summarizer_1.Summarizer {
55
54
  fs_1.default.writeFileSync(this.config.outputPath, JSON.stringify(ultimate, json_1.jsonReplacer));
56
55
  console.log((0, print_1.ultimateStats2String)(ultimate));
57
56
  if (this.config.graphOutputPath) {
58
- (0, graph_1.writeGraphOutput)(ultimate, this.config.graphOutputPath);
57
+ await (0, graph_1.writeGraphOutput)(ultimate, this.config.graphOutputPath);
59
58
  }
60
59
  return ultimate;
61
60
  }
@@ -17,4 +17,5 @@ export interface BenchmarkCliOptions {
17
17
  'sampling-strategy': string;
18
18
  cfg?: boolean;
19
19
  cg?: boolean;
20
+ 'no-extra-phases'?: boolean;
20
21
  }
@@ -76,7 +76,8 @@ async function benchmark() {
76
76
  '--sampling-strategy', options['sampling-strategy'],
77
77
  ...(options.seed ? ['--seed', options.seed] : []),
78
78
  ...(options.cfg ? ['--cfg'] : []),
79
- ...(options.cg ? ['--cg'] : [])
79
+ ...(options.cg ? ['--cg'] : []),
80
+ ...(options['no-extra-phases'] ? ['--no-extra-phases'] : [])
80
81
  ]);
81
82
  const runs = options.runs ?? 1;
82
83
  for (let i = 1; i <= runs; i++) {
@@ -12,6 +12,7 @@ export interface SingleBenchmarkCliOptions {
12
12
  'max-slices': number;
13
13
  cfg: boolean;
14
14
  cg: boolean;
15
+ 'no-extra-phases': boolean;
15
16
  threshold?: number;
16
17
  'sampling-strategy': string;
17
18
  seed?: string;
@@ -73,8 +73,18 @@ async function benchmark() {
73
73
  }
74
74
  if (options['dataframe-shape-inference']) {
75
75
  console.log(`${prefix} Performing shape inference for data frames`);
76
- slicer.inferDataFrameShapes();
77
- console.log(`${prefix} Completed data frame shape inference`);
76
+ // the inference is not what the benchmark is about, so a failure costs its numbers and nothing else
77
+ try {
78
+ slicer.inferDataFrameShapes();
79
+ console.log(`${prefix} Completed data frame shape inference`);
80
+ }
81
+ catch (e) {
82
+ console.log(`${prefix} Skipping data frame shape inference: ${e instanceof Error ? e.message : String(e)}`);
83
+ }
84
+ }
85
+ console.log(`${prefix} Measuring the additional phases (dependencies query, linter, calibration)`);
86
+ if (!options['no-extra-phases']) {
87
+ await slicer.measureAdditionalPhases();
78
88
  }
79
89
  const { stats } = slicer.finish();
80
90
  const output = {
@@ -109,6 +109,11 @@ export declare const benchmarkOptions: [{
109
109
  readonly name: "cg";
110
110
  readonly type: BooleanConstructor;
111
111
  readonly description: "Extract the call graph of the file (benchmark it too)";
112
+ }, {
113
+ readonly name: "no-extra-phases";
114
+ readonly type: BooleanConstructor;
115
+ readonly description: "Skip the dependencies query, the linter run and the calibration, which cost suite runtime";
116
+ readonly defaultValue: false;
112
117
  }];
113
118
  export declare const benchmarkHelperOptions: [{
114
119
  readonly name: "verbose";
@@ -190,6 +195,11 @@ export declare const benchmarkHelperOptions: [{
190
195
  readonly description: "Which strategy to use, when sampling is enabled";
191
196
  readonly defaultValue: "random";
192
197
  readonly typeLabel: "{underline random/equidistant}";
198
+ }, {
199
+ readonly name: "no-extra-phases";
200
+ readonly type: BooleanConstructor;
201
+ readonly description: "Skip the dependencies query, the linter run and the calibration, which cost suite runtime";
202
+ readonly defaultValue: false;
193
203
  }, {
194
204
  readonly name: "seed";
195
205
  readonly type: StringConstructor;
@@ -27,7 +27,8 @@ exports.benchmarkOptions = [
27
27
  { name: 'per-file-time-limit', type: Number, description: 'Time limit in milliseconds to process single file (disabled by default)', defaultValue: undefined, typeLabel: '{underline number}' },
28
28
  { name: 'sampling-strategy', type: String, description: 'Which strategy to use, when sampling is enabled', defaultValue: 'random', typeLabel: '{underline random/equidistant}' },
29
29
  { name: 'cfg', alias: 'c', type: Boolean, description: 'Extract the control flow graph of the file (benchmark it too)' },
30
- { name: 'cg', type: Boolean, description: 'Extract the call graph of the file (benchmark it too)' }
30
+ { name: 'cg', type: Boolean, description: 'Extract the call graph of the file (benchmark it too)' },
31
+ { name: 'no-extra-phases', type: Boolean, description: 'Skip the dependencies query, the linter run and the calibration, which cost suite runtime', defaultValue: false },
31
32
  ];
32
33
  exports.benchmarkHelperOptions = [
33
34
  { name: 'verbose', alias: 'v', type: Boolean, description: 'Run with verbose logging [do not use for the real benchmark as this affects the time measurements, but only to find errors]' },
@@ -44,6 +45,7 @@ exports.benchmarkHelperOptions = [
44
45
  { name: 'max-slices', type: Number, description: 'If file has more than passed number of slices, the file is not processed', defaultValue: -1, typeLabel: '{underline number}' },
45
46
  { name: 'threshold', alias: 't', type: Number, description: 'How many re-visits of the same node are ok?', defaultValue: undefined, typeLabel: '{underline number}' },
46
47
  { name: 'sampling-strategy', type: String, description: 'Which strategy to use, when sampling is enabled', defaultValue: 'random', typeLabel: '{underline random/equidistant}' },
48
+ { name: 'no-extra-phases', type: Boolean, description: 'Skip the dependencies query, the linter run and the calibration, which cost suite runtime', defaultValue: false },
47
49
  { name: 'seed', type: String, description: 'The random seed for sampling the slicing criteria if a maximum is set' },
48
50
  ];
49
51
  exports.exportQuadsOptions = [
@@ -224,6 +224,11 @@ declare const _scripts: {
224
224
  readonly name: "cg";
225
225
  readonly type: BooleanConstructor;
226
226
  readonly description: "Extract the call graph of the file (benchmark it too)";
227
+ }, {
228
+ readonly name: "no-extra-phases";
229
+ readonly type: BooleanConstructor;
230
+ readonly description: "Skip the dependencies query, the linter run and the calibration, which cost suite runtime";
231
+ readonly defaultValue: false;
227
232
  }];
228
233
  };
229
234
  'benchmark-helper': {
@@ -311,6 +316,11 @@ declare const _scripts: {
311
316
  readonly description: "Which strategy to use, when sampling is enabled";
312
317
  readonly defaultValue: "random";
313
318
  readonly typeLabel: "{underline random/equidistant}";
319
+ }, {
320
+ readonly name: "no-extra-phases";
321
+ readonly type: BooleanConstructor;
322
+ readonly description: "Skip the dependencies query, the linter run and the calibration, which cost suite runtime";
323
+ readonly defaultValue: false;
314
324
  }, {
315
325
  readonly name: "seed";
316
326
  readonly type: StringConstructor;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * An append-only builder for a {@link ControlFlowGraph}, used while folding the AST.
3
+ * @module
4
+ */
5
+ import type { NodeId } from '../r-bridge/lang-4.x/ast/model/processing/node-id';
6
+ import type { CfgEdge } from './control-flow-graph';
7
+ import { CfgVertex, ControlFlowGraph } from './control-flow-graph';
8
+ /**
9
+ * Records the vertices and edges of a control flow graph instead of building it, as the bottom-up fold would
10
+ * copy an eager graph once per nesting level. {@link CfgBuilder#mergeWith|mergeWith()} only references the other
11
+ * builder, {@link CfgBuilder#materialize|materialize()} replays everything once in recording order &mdash; the
12
+ * order an eager merge produced, which the vertex order of a function definition's children relies on.
13
+ */
14
+ export declare class CfgBuilder {
15
+ private readonly operations;
16
+ addVertex(vertex: CfgVertex, rootVertex?: boolean): this;
17
+ addEdge(from: NodeId, to: NodeId, edge: CfgEdge): this;
18
+ /**
19
+ * Record that the other builder is part of this one, it must not be modified afterwards.
20
+ * @param other - the builder to include
21
+ * @param forceNested - should its vertices count as nested (e.g., within a function definition)
22
+ */
23
+ mergeWith(other: CfgBuilder, forceNested?: boolean): this;
24
+ /** The last vertex recorded for the given id, searching the merged builders only if we hold none. */
25
+ getVertex(id: NodeId): CfgVertex | undefined;
26
+ /** The ids of all vertices that are not nested, in insertion order. */
27
+ rootIds(collected?: Set<NodeId>): ReadonlySet<NodeId>;
28
+ /** Replays all recorded operations into a {@link ControlFlowGraph}. */
29
+ materialize(graph?: ControlFlowGraph, nested?: boolean): ControlFlowGraph;
30
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CfgBuilder = void 0;
4
+ const control_flow_graph_1 = require("./control-flow-graph");
5
+ /**
6
+ * Records the vertices and edges of a control flow graph instead of building it, as the bottom-up fold would
7
+ * copy an eager graph once per nesting level. {@link CfgBuilder#mergeWith|mergeWith()} only references the other
8
+ * builder, {@link CfgBuilder#materialize|materialize()} replays everything once in recording order &mdash; the
9
+ * order an eager merge produced, which the vertex order of a function definition's children relies on.
10
+ */
11
+ class CfgBuilder {
12
+ operations = [];
13
+ addVertex(vertex, rootVertex = true) {
14
+ this.operations.push({ kind: 0 /* BuilderOperationType.Vertex */, vertex, root: rootVertex });
15
+ return this;
16
+ }
17
+ addEdge(from, to, edge) {
18
+ this.operations.push({ kind: 1 /* BuilderOperationType.Edge */, from, to, edge });
19
+ return this;
20
+ }
21
+ /**
22
+ * Record that the other builder is part of this one, it must not be modified afterwards.
23
+ * @param other - the builder to include
24
+ * @param forceNested - should its vertices count as nested (e.g., within a function definition)
25
+ */
26
+ mergeWith(other, forceNested = false) {
27
+ this.operations.push({ kind: 2 /* BuilderOperationType.Merge */, other, nested: forceNested });
28
+ return this;
29
+ }
30
+ /** The last vertex recorded for the given id, searching the merged builders only if we hold none. */
31
+ getVertex(id) {
32
+ for (let i = this.operations.length - 1; i >= 0; i--) {
33
+ const operation = this.operations[i];
34
+ if (operation.kind === 0 /* BuilderOperationType.Vertex */) {
35
+ if (control_flow_graph_1.CfgVertex.getId(operation.vertex) === id) {
36
+ return operation.vertex;
37
+ }
38
+ }
39
+ else if (operation.kind === 2 /* BuilderOperationType.Merge */) {
40
+ const found = operation.other.getVertex(id);
41
+ if (found !== undefined) {
42
+ return found;
43
+ }
44
+ }
45
+ }
46
+ return undefined;
47
+ }
48
+ /** The ids of all vertices that are not nested, in insertion order. */
49
+ rootIds(collected = new Set()) {
50
+ for (const operation of this.operations) {
51
+ if (operation.kind === 0 /* BuilderOperationType.Vertex */) {
52
+ if (operation.root) {
53
+ collected.add(control_flow_graph_1.CfgVertex.getId(operation.vertex));
54
+ }
55
+ }
56
+ else if (operation.kind === 2 /* BuilderOperationType.Merge */ && !operation.nested) {
57
+ operation.other.rootIds(collected);
58
+ }
59
+ }
60
+ return collected;
61
+ }
62
+ /** Replays all recorded operations into a {@link ControlFlowGraph}. */
63
+ materialize(graph = new control_flow_graph_1.ControlFlowGraph(), nested = false) {
64
+ for (const operation of this.operations) {
65
+ if (operation.kind === 0 /* BuilderOperationType.Vertex */) {
66
+ graph.addVertex(operation.vertex, operation.root && !nested);
67
+ }
68
+ else if (operation.kind === 1 /* BuilderOperationType.Edge */) {
69
+ graph.addEdge(operation.from, operation.to, operation.edge);
70
+ }
71
+ else {
72
+ operation.other.materialize(graph, nested || operation.nested);
73
+ }
74
+ }
75
+ return graph;
76
+ }
77
+ }
78
+ exports.CfgBuilder = CfgBuilder;
79
+ //# sourceMappingURL=cfg-builder.js.map