Skip to content

Commit

Permalink
New Code-Style Conventions (#975)
Browse files Browse the repository at this point in the history
  • Loading branch information
EagleoutIce authored Sep 16, 2024
2 parents 1b95cbc + 7c71435 commit 3062314
Show file tree
Hide file tree
Showing 351 changed files with 9,854 additions and 9,837 deletions.
27 changes: 22 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-angular": "^19.3.0",
"@eagleoutice/eslint-config-flowr": "^1.0.8",
"@eagleoutice/eslint-config-flowr": "^1.0.11",
"@j-ulrich/release-it-regex-bumper": "^5.1.0",
"@stylistic/eslint-plugin": "^2.1.0",
"@stylistic/eslint-plugin-plus": "^2.1.0",
Expand Down
252 changes: 126 additions & 126 deletions src/benchmark/slicer.ts

Large diffs are not rendered by default.

88 changes: 44 additions & 44 deletions src/benchmark/stats/print.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,95 +2,95 @@
* This module is tasked with processing the results of the benchmarking (see {@link SummarizedSlicerStats}).
* @module
*/
import type { ElapsedTime, PerSliceMeasurements } from './stats'
import type { Reduction, SummarizedPerSliceStats, SummarizedSlicerStats, UltimateSlicerStats } from '../summarizer/data'
import { guard } from '../../util/assert'
import type { SummarizedMeasurement } from '../../util/summarizer'
import type { ElapsedTime, PerSliceMeasurements } from './stats';
import type { Reduction, SummarizedPerSliceStats, SummarizedSlicerStats, UltimateSlicerStats } from '../summarizer/data';
import { guard } from '../../util/assert';
import type { SummarizedMeasurement } from '../../util/summarizer';

const padSize = 15
const padSize = 15;

function pad<T>(string: T) {
return String(string).padStart(padSize, ' ')
return String(string).padStart(padSize, ' ');
}

export function formatNanoseconds(nanoseconds: bigint | number): string {
if(nanoseconds < 0) {
return '??'
return '??';
} else if(!Number.isFinite(nanoseconds)) {
return nanoseconds > 0 ? '∞' : '-∞'
return nanoseconds > 0 ? '∞' : '-∞';
}

const wholeNanos = typeof nanoseconds === 'bigint' ? nanoseconds : BigInt(Math.round(nanoseconds))
const nanos = wholeNanos % BigInt(1e+6)
const wholeMillis = wholeNanos / BigInt(1e+6)
const millis = wholeMillis % BigInt(1000)
const wholeSeconds = wholeMillis / BigInt(1000)
const wholeNanos = typeof nanoseconds === 'bigint' ? nanoseconds : BigInt(Math.round(nanoseconds));
const nanos = wholeNanos % BigInt(1e+6);
const wholeMillis = wholeNanos / BigInt(1e+6);
const millis = wholeMillis % BigInt(1000);
const wholeSeconds = wholeMillis / BigInt(1000);
if(wholeSeconds > 0){
const nanoString = nanos > 0 ? `:${nanos}` : ''
return pad(`${wholeSeconds}.${String(millis).padStart(3, '0')}${nanoString} s`)
const nanoString = nanos > 0 ? `:${nanos}` : '';
return pad(`${wholeSeconds}.${String(millis).padStart(3, '0')}${nanoString} s`);
} else {
return pad(`${millis}:${String(nanos).padStart(6, '0')}ms`)
return pad(`${millis}:${String(nanos).padStart(6, '0')}ms`);
}
}


function print<K>(measurements: Map<K, ElapsedTime>, key: K) {
const time = measurements.get(key)
guard(time !== undefined, `Measurement for ${JSON.stringify(key)} not found`)
return formatNanoseconds(time)
const time = measurements.get(key);
guard(time !== undefined, `Measurement for ${JSON.stringify(key)} not found`);
return formatNanoseconds(time);
}

function formatSummarizedTimeMeasure(measure: SummarizedMeasurement | undefined) {
if(measure === undefined) {
return '??'
return '??';
}
return `${formatNanoseconds(measure.min)} - ${formatNanoseconds(measure.max)} (median: ${formatNanoseconds(measure.median)}, mean: ${formatNanoseconds(measure.mean)}, std: ${formatNanoseconds(measure.std)})`
return `${formatNanoseconds(measure.min)} - ${formatNanoseconds(measure.max)} (median: ${formatNanoseconds(measure.median)}, mean: ${formatNanoseconds(measure.mean)}, std: ${formatNanoseconds(measure.std)})`;
}

function roundTo(num: number, digits = 4): number {
const factor = Math.pow(10, digits)
return Math.round(num * factor) / factor
const factor = Math.pow(10, digits);
return Math.round(num * factor) / factor;
}

function asPercentage(num: number): string {
if(isNaN(num)) {
return '??%'
return '??%';
}
return pad(`${roundTo(num * 100, 3)}%`)
return pad(`${roundTo(num * 100, 3)}%`);
}

function asFloat(num: number): string {
return pad(roundTo(num))
return pad(roundTo(num));
}

function formatSummarizedMeasure(measure: SummarizedMeasurement | undefined, fmt: (num: number) => string = asFloat) {
if(measure === undefined) {
return '??'
return '??';
}
return `${fmt(measure.min)} - ${fmt(measure.max)} (median: ${fmt(measure.median)}, mean: ${fmt(measure.mean)}, std: ${fmt(measure.std)})`
return `${fmt(measure.min)} - ${fmt(measure.max)} (median: ${fmt(measure.median)}, mean: ${fmt(measure.mean)}, std: ${fmt(measure.std)})`;
}

function printSummarizedMeasurements(stats: SummarizedPerSliceStats, key: PerSliceMeasurements): string {
const measure = stats.measurements.get(key)
guard(measure !== undefined, `Measurement for ${JSON.stringify(key)} not found`)
return formatSummarizedTimeMeasure(measure)
const measure = stats.measurements.get(key);
guard(measure !== undefined, `Measurement for ${JSON.stringify(key)} not found`);
return formatSummarizedTimeMeasure(measure);
}

function printCountSummarizedMeasurements(stats: SummarizedMeasurement): string {
const range = `${stats.min} - ${stats.max}`.padStart(padSize, ' ')
return `${range} (median: ${stats.median}, mean: ${stats.mean}, std: ${stats.std})`
const range = `${stats.min} - ${stats.max}`.padStart(padSize, ' ');
return `${range} (median: ${stats.median}, mean: ${stats.mean}, std: ${stats.std})`;
}

const units = ['bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']
const units = ['bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];

// based on https://stackoverflow.com/a/39906526
function convertNumberToNiceBytes(x: number){
let n = Math.abs(x)
let l = 0
let n = Math.abs(x);
let l = 0;
while(n >= 1024 && ++l){
n = n/1024
n = n/1024;
}
return pad((x < 0 ? '-' : '') + n.toFixed(n < 10 && l > 0 ? 1 : 0) + ' ' + units[l])
return pad((x < 0 ? '-' : '') + n.toFixed(n < 10 && l > 0 ? 1 : 0) + ' ' + units[l]);
}

/**
Expand All @@ -113,7 +113,7 @@ Dataflow creation per R token:${formatNanoseconds(stats.dataflowTimePerToken.raw
Total common time per token: ${formatNanoseconds(stats.totalCommonTimePerToken.normalized)}
Total common time per R token:${formatNanoseconds(stats.totalCommonTimePerToken.raw)}
Slicing summary for ${stats.perSliceMeasurements.numberOfSlices} slice${stats.perSliceMeasurements.numberOfSlices !== 1 ? 's' : ''}:`
Slicing summary for ${stats.perSliceMeasurements.numberOfSlices} slice${stats.perSliceMeasurements.numberOfSlices !== 1 ? 's' : ''}:`;
if(stats.perSliceMeasurements.numberOfSlices > 0) {
result += `
Total: ${printSummarizedMeasurements(stats.perSliceMeasurements, 'total')}
Expand All @@ -137,7 +137,7 @@ Slicing summary for ${stats.perSliceMeasurements.numberOfSlices} slice${stats.pe
Normalized R tokens: ${printCountSummarizedMeasurements(stats.perSliceMeasurements.sliceSize.normalizedTokens)}
Normalized R tokens (w/o comments): ${printCountSummarizedMeasurements(stats.perSliceMeasurements.sliceSize.normalizedTokensNoComments)}
Number of dataflow nodes: ${printCountSummarizedMeasurements(stats.perSliceMeasurements.sliceSize.dataflowNodes)}
`
`;
}

return `${result}
Expand All @@ -161,7 +161,7 @@ Dataflow:
Number of edges: ${pad(stats.dataflow.numberOfEdges)}
Number of calls: ${pad(stats.dataflow.numberOfCalls)}
Number of function defs: ${pad(stats.dataflow.numberOfFunctionDefinitions)}
Size of graph: ${convertNumberToNiceBytes(stats.dataflow.sizeOfObject)}`
Size of graph: ${convertNumberToNiceBytes(stats.dataflow.sizeOfObject)}`;
}

export function ultimateStats2String(stats: UltimateSlicerStats): string {
Expand All @@ -178,7 +178,7 @@ export function ultimateStats2String(stats: UltimateSlicerStats): string {
Failed to Re-Parse: ${pad(stats.failedToRepParse)}/${stats.totalSlices}
Times hit Threshold: ${pad(stats.timesHitThreshold)}/${stats.totalSlices}
${reduction2String('Reductions', stats.reduction)}
${reduction2String('Reductions without comments and empty lines', stats.reductionNoFluff)}` : 'No slices'
${reduction2String('Reductions without comments and empty lines', stats.reductionNoFluff)}` : 'No slices';

// Used Slice Criteria Sizes: ${formatSummarizedMeasure(stats.perSliceMeasurements.sliceCriteriaSizes)}
return `
Expand Down Expand Up @@ -219,7 +219,7 @@ Dataflow:
Number of calls: ${formatSummarizedMeasure(stats.dataflow.numberOfCalls)}
Number of function defs: ${formatSummarizedMeasure(stats.dataflow.numberOfFunctionDefinitions)}
Size of graph: ${formatSummarizedMeasure(stats.dataflow.sizeOfObject, convertNumberToNiceBytes)}
`
`;
}

function reduction2String(title: string, reduction: Reduction<SummarizedMeasurement>) {
Expand All @@ -231,5 +231,5 @@ function reduction2String(title: string, reduction: Reduction<SummarizedMeasurem
Number of non whitespace characters: ${formatSummarizedMeasure(reduction.numberOfNonWhitespaceCharacters, asPercentage)}
Number of R tokens: ${formatSummarizedMeasure(reduction.numberOfRTokens, asPercentage)}
Normalized R tokens: ${formatSummarizedMeasure(reduction.numberOfNormalizedTokens, asPercentage)}
Number of dataflow nodes: ${formatSummarizedMeasure(reduction.numberOfDataflowNodes, asPercentage)}`
Number of dataflow nodes: ${formatSummarizedMeasure(reduction.numberOfDataflowNodes, asPercentage)}`;
}
38 changes: 19 additions & 19 deletions src/benchmark/stats/size-of.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import type { IEnvironment } from '../../dataflow/environments/environment'
import { BuiltInEnvironment } from '../../dataflow/environments/environment'
import type { DataflowGraph } from '../../dataflow/graph/graph'
import type { DataflowGraphVertexInfo } from '../../dataflow/graph/vertex'
import { VertexType } from '../../dataflow/graph/vertex'
import type { Identifier, IdentifierDefinition } from '../../dataflow/environments/identifier'
import sizeof from 'object-sizeof'
import type { IEnvironment } from '../../dataflow/environments/environment';
import { BuiltInEnvironment } from '../../dataflow/environments/environment';
import type { DataflowGraph } from '../../dataflow/graph/graph';
import type { DataflowGraphVertexInfo } from '../../dataflow/graph/vertex';
import { VertexType } from '../../dataflow/graph/vertex';
import type { Identifier, IdentifierDefinition } from '../../dataflow/environments/identifier';
import sizeof from 'object-sizeof';

/* we have to kill all processors linked in the default environment as they cannot be serialized and they are shared anyway */
function killBuiltInEnv(env: IEnvironment | undefined): IEnvironment {
if(env === undefined) {
return undefined as unknown as IEnvironment
return undefined as unknown as IEnvironment;
} else if(env.id === BuiltInEnvironment.id) {
/* in this case, the reference would be shared for sure */
return {
id: env.id,
parent: killBuiltInEnv(env.parent),
memory: new Map<Identifier, IdentifierDefinition[]>()
}
};
}

const memory = new Map<Identifier, IdentifierDefinition[]>()
const memory = new Map<Identifier, IdentifierDefinition[]>();
for(const [k, v] of env.memory) {
memory.set(k, v.filter(v => !v.kind.startsWith('built-in') && !('processor' in v)))
memory.set(k, v.filter(v => !v.kind.startsWith('built-in') && !('processor' in v)));
}

return {
id: env.id,
parent: killBuiltInEnv(env.parent),
memory
}
};
}

/** Returns the size of the given df graph in bytes (without sharing in-memory) */
export function getSizeOfDfGraph(df: DataflowGraph): number {
const verts = []
const verts = [];
for(const [, v] of df.vertices(true)) {
let vertex: DataflowGraphVertexInfo = v
let vertex: DataflowGraphVertexInfo = v;
if(vertex.environment) {
vertex = {
...vertex,
environment: {
...vertex.environment,
current: killBuiltInEnv(v.environment?.current)
}
} as DataflowGraphVertexInfo
} as DataflowGraphVertexInfo;
}

if(vertex.tag === VertexType.FunctionDefinition) {
Expand All @@ -56,17 +56,17 @@ export function getSizeOfDfGraph(df: DataflowGraph): number {
current: killBuiltInEnv(vertex.subflow.environment.current)
}
}
} as DataflowGraphVertexInfo
} as DataflowGraphVertexInfo;
}

vertex = {
...vertex,
/* shared anyway by using constants */
tag: 0 as unknown
} as DataflowGraphVertexInfo
} as DataflowGraphVertexInfo;

verts.push(vertex)
verts.push(vertex);
}

return sizeof([...verts, ...df.edges()])
return sizeof([...verts, ...df.edges()]);
}
16 changes: 8 additions & 8 deletions src/benchmark/stats/stats.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { SingleSlicingCriterion, SlicingCriteria } from '../../slicing/criterion/parse'
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id'
import type { ReconstructionResult } from '../../reconstruct/reconstruct'
import type { RParseRequestFromFile, RParseRequestFromText } from '../../r-bridge/retriever'
import type { TimePerToken } from '../summarizer/data'
import type { MergeableRecord } from '../../util/objects'
import type { SingleSlicingCriterion, SlicingCriteria } from '../../slicing/criterion/parse';
import type { NodeId } from '../../r-bridge/lang-4.x/ast/model/processing/node-id';
import type { ReconstructionResult } from '../../reconstruct/reconstruct';
import type { RParseRequestFromFile, RParseRequestFromText } from '../../r-bridge/retriever';
import type { TimePerToken } from '../summarizer/data';
import type { MergeableRecord } from '../../util/objects';

export const CommonSlicerMeasurements = ['initialize R session', 'retrieve AST from R code', 'normalize R AST', 'produce dataflow information', 'close R session', 'total'] as const
export const CommonSlicerMeasurements = ['initialize R session', 'retrieve AST from R code', 'normalize R AST', 'produce dataflow information', 'close R session', 'total'] as const;
export type CommonSlicerMeasurements = typeof CommonSlicerMeasurements[number]

export const PerSliceMeasurements = ['static slicing', 'reconstruct code', 'total'] as const
export const PerSliceMeasurements = ['static slicing', 'reconstruct code', 'total'] as const;
export type PerSliceMeasurements = typeof PerSliceMeasurements[number]

export type ElapsedTime = bigint
Expand Down
Loading

2 comments on commit 3062314

@github-actions
Copy link

Choose a reason for hiding this comment

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

"artificial" Benchmark Suite

Benchmark suite Current: 3062314 Previous: e97ab14 Ratio
Retrieve AST from R code 232.4923650909091 ms (97.187631930298) 237.97672204545452 ms (100.95361539859664) 0.98
Normalize R AST 19.466555045454548 ms (33.736368086053005) 21.414143136363638 ms (39.56891598363369) 0.91
Produce dataflow information 37.893814954545455 ms (82.32893642574784) 38.950916863636365 ms (85.69610850964092) 0.97
Total per-file 795.5689836363637 ms (1400.478976462602) 808.1631112727273 ms (1428.688046281115) 0.98
Static slicing 2.1992566492390675 ms (1.3575146053864215) 2.228467730535544 ms (1.3740018187972964) 0.99
Reconstruct code 0.2207418331184341 ms (0.167630688925279) 0.2245747020074741 ms (0.17586130505481137) 0.98
Total per-slice 2.435953880787887 ms (1.4126092388931744) 2.470040222573707 ms (1.4254046625840677) 0.99
failed to reconstruct/re-parse 0 # 0 # 1
times hit threshold 0 # 0 # 1
reduction (characters) 0.7869360165281424 # 0.7869360165281424 # 1
reduction (normalized tokens) 0.7639690077689504 # 0.7639690077689504 # 1
memory (df-graph) 147.42458274147728 KiB (358.6827375397903) 147.42458274147728 KiB (358.6827375397903) 1

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

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

"social-science" Benchmark Suite

Benchmark suite Current: 3062314 Previous: e97ab14 Ratio
Retrieve AST from R code 239.06658124 ms (46.082310477965144) 230.45514896 ms (41.928890449506795) 1.04
Normalize R AST 22.053598559999998 ms (16.820596016263387) 21.83893728 ms (16.824930859182228) 1.01
Produce dataflow information 74.28021952 ms (87.91680594714569) 71.77401414 ms (84.7721694767239) 1.03
Total per-file 11179.5083419 ms (52856.318588020156) 10637.351617459999 ms (50105.335952081325) 1.05
Static slicing 22.187314202443417 ms (79.14623282310089) 21.13796129326044 ms (74.99919647035496) 1.05
Reconstruct code 0.23071416992172375 ms (0.1430409052947364) 0.20996977181571297 ms (0.1323410404638652) 1.10
Total per-slice 22.425645441180524 ms (79.1681873257993) 21.355262023955028 ms (75.02211455722146) 1.05
failed to reconstruct/re-parse 0 # 0 # 1
times hit threshold 0 # 0 # 1
reduction (characters) 0.8719618340615195 # 0.8719618340615195 # 1
reduction (normalized tokens) 0.810633662275233 # 0.810633662275233 # 1
memory (df-graph) 145.6434765625 KiB (153.49028997815503) 145.6434765625 KiB (153.49028997815503) 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.