Skip to content

Commit

Permalink
Merge pull request #1 from vezenovm/mv/temp-same-content
Browse files Browse the repository at this point in the history
Temp check using same content
  • Loading branch information
vezenovm committed Apr 23, 2024
2 parents f80ea70 + 80405a3 commit d4cdc54
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 169 deletions.
56 changes: 44 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,13 +387,25 @@ function run() {
core.info(`Loading gas reports from "${localReportPath}"`);
const compareContent = fs.readFileSync(localReportPath, "utf8");
referenceContent !== null && referenceContent !== void 0 ? referenceContent : (referenceContent = compareContent); // if no source gas reports were loaded, defaults to the current gas reports
core.info(`Mapping reference gas reports`);
const referenceReports = (0, report_1.loadReports)(referenceContent);
// TODO: Bring this back after master has a correct report as it currently
// has a report with only "main" report names
// const referenceReports = loadReports(referenceContent);
core.info(`Mapping compared gas reports`);
const compareReports = (0, report_1.loadReports)(compareContent);
core.info(`Got ${compareReports.programs.length} programs`);
core.info(`Mapping reference gas reports`);
core.info(`Making dummy reference report`);
const referenceReports = compareReports.programs.map((program) => {
const circuitReport = { name: "main", acir_opcodes: 1, circuit_size: 1 };
const programReport = {
package_name: program.package_name,
functions: [circuitReport],
};
return programReport;
});
core.endGroup();
core.startGroup("Compute gas diff");
const diffRows = (0, report_1.computeProgramDiffs)(referenceReports.programs[0].functions, compareReports.programs[0].functions);
const diffRows = (0, report_1.computeProgramDiffs)(referenceReports, compareReports.programs);
core.info(`Format markdown of ${diffRows.length} diffs`);
const markdown = (0, program_1.formatMarkdownDiff)(header, diffRows, repository, github_1.context.sha, refCommitHash, summaryQuantile);
core.info(`Format shell of ${diffRows.length} diffs`);
Expand Down Expand Up @@ -451,30 +463,33 @@ const loadReports = (content) => {
};
exports.loadReports = loadReports;
const computedWorkspaceDiff = (sourceReport, compareReport) => ({
programs: (0, exports.computeProgramDiffs)(sourceReport.programs[0].functions, compareReport.programs[0].functions),
programs: (0, exports.computeProgramDiffs)(sourceReport.programs, compareReport.programs),
contracts: (0, exports.computeContractDiffs)(sourceReport.contracts, compareReport.contracts),
});
exports.computedWorkspaceDiff = computedWorkspaceDiff;
const computeProgramDiffs = (sourceReports, compareReports) => {
const sourceReportNames = sourceReports.map((report) => report.name);
const sourceReportNames = sourceReports.map((report) => report.package_name);
const commonReportNames = compareReports
.map((report) => report.name)
.map((report) => report.package_name)
.filter((name) => sourceReportNames.includes(name));
return commonReportNames
.map((reportName) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const srcReport = sourceReports.find((report) => report.name == reportName);
const srcReport = sourceReports.find((report) => report.package_name == reportName);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const cmpReport = compareReports.find((report) => report.name == reportName);
return computeProgramDiff(srcReport, cmpReport);
const cmpReport = compareReports.find((report) => report.package_name == reportName);
// For now we fetch just the main of each program
return computeCircuitDiff(srcReport.functions[0], cmpReport.functions[0], reportName);
})
.filter((diff) => !isEmptyDiff(diff))
.sort((diff1, diff2) => Math.max(diff2.circuit_size.percentage) - Math.max(diff1.circuit_size.percentage));
};
exports.computeProgramDiffs = computeProgramDiffs;
const computeProgramDiff = (sourceReport, compareReport) => {
const computeCircuitDiff = (sourceReport, compareReport,
// We want the name of the package that represents the entire program in our report
reportName) => {
return {
name: sourceReport.name,
name: reportName,
acir_opcodes: (0, exports.variation)(compareReport.acir_opcodes, sourceReport.acir_opcodes),
circuit_size: (0, exports.variation)(compareReport.circuit_size, sourceReport.circuit_size),
};
Expand All @@ -499,7 +514,24 @@ const computeContractDiffs = (sourceReports, compareReports) => {
};
exports.computeContractDiffs = computeContractDiffs;
const computeContractDiff = (sourceReport, compareReport) => {
const functionDiffs = (0, exports.computeProgramDiffs)(sourceReport.functions[0].functions, compareReport.functions[0].functions);
// TODO(https://github.com/noir-lang/noir/issues/4720): Settle on how to display contract functions with non-inlined Acir calls
// Right now we assume each contract function does not have non-inlined functions.
// Thus, we simply re-assign each `CircuitReport` to a `ProgramReport` to easily reuse `computeProgramDiffs`
const sourceFunctionsAsProgram = sourceReport.functions.map((func) => {
const programReport = {
package_name: func.name,
functions: [func],
};
return programReport;
});
const compareFunctionsAsProgram = compareReport.functions.map((func) => {
const programReport = {
package_name: func.name,
functions: [func],
};
return programReport;
});
const functionDiffs = (0, exports.computeProgramDiffs)(sourceFunctionsAsProgram, compareFunctionsAsProgram);
return {
name: sourceReport.name,
functions: functionDiffs,
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { context, getOctokit } from "@actions/github";

import { formatMarkdownDiff, formatShellDiff } from "./format/program";
import { loadReports, computeProgramDiffs } from "./report";
import { CircuitReport, ProgramReport, WorkspaceReport } from "./types";

// import { isSortCriteriaValid, isSortOrdersValid } from "./types";

Expand Down Expand Up @@ -106,14 +107,26 @@ async function run() {
const compareContent = fs.readFileSync(localReportPath, "utf8");
referenceContent ??= compareContent; // if no source gas reports were loaded, defaults to the current gas reports

core.info(`Mapping reference gas reports`);
const referenceReports = loadReports(referenceContent);
// TODO: Bring this back after master has a correct report as it currently
// has a report with only "main" report names
// const referenceReports = loadReports(referenceContent);
core.info(`Mapping compared gas reports`);
const compareReports = loadReports(compareContent);
core.info(`Got ${compareReports.programs.length} programs`);
core.info(`Mapping reference gas reports`);
core.info(`Making dummy reference report`);
const referenceReports = compareReports.programs.map((program) => {
const circuitReport: CircuitReport = { name: "main", acir_opcodes: 1, circuit_size: 1 };
const programReport: ProgramReport = {
package_name: program.package_name,
functions: [circuitReport],
};
return programReport;
});
core.endGroup();

core.startGroup("Compute gas diff");
const diffRows = computeProgramDiffs(referenceReports.programs, compareReports.programs);
const diffRows = computeProgramDiffs(referenceReports, compareReports.programs);
core.info(`Format markdown of ${diffRows.length} diffs`);
const markdown = formatMarkdownDiff(
header,
Expand Down
27 changes: 22 additions & 5 deletions src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ export const computeProgramDiffs = (
sourceReports: ProgramReport[],
compareReports: ProgramReport[]
): DiffProgram[] => {
const sourceReportNames = sourceReports.map((report) => report.name);
const sourceReportNames = sourceReports.map((report) => report.package_name);
const commonReportNames = compareReports
.map((report) => report.name)
.map((report) => report.package_name)
.filter((name) => sourceReportNames.includes(name));

return commonReportNames
.map((reportName) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const srcReport = sourceReports.find((report) => report.name == reportName)!;
const srcReport = sourceReports.find((report) => report.package_name == reportName)!;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const cmpReport = compareReports.find((report) => report.name == reportName)!;
const cmpReport = compareReports.find((report) => report.package_name == reportName)!;

// For now we fetch just the main of each program
return computeCircuitDiff(srcReport.functions[0], cmpReport.functions[0], reportName);
Expand Down Expand Up @@ -109,7 +109,24 @@ const computeContractDiff = (
sourceReport: ContractReport,
compareReport: ContractReport
): ContractDiffReport => {
const functionDiffs = computeProgramDiffs(sourceReport.functions, compareReport.functions);
// TODO(https://github.com/noir-lang/noir/issues/4720): Settle on how to display contract functions with non-inlined Acir calls
// Right now we assume each contract function does not have non-inlined functions.
// Thus, we simply re-assign each `CircuitReport` to a `ProgramReport` to easily reuse `computeProgramDiffs`
const sourceFunctionsAsProgram = sourceReport.functions.map((func) => {
const programReport: ProgramReport = {
package_name: func.name,
functions: [func],
};
return programReport;
});
const compareFunctionsAsProgram = compareReport.functions.map((func) => {
const programReport: ProgramReport = {
package_name: func.name,
functions: [func],
};
return programReport;
});
const functionDiffs = computeProgramDiffs(sourceFunctionsAsProgram, compareFunctionsAsProgram);

return {
name: sourceReport.name,
Expand Down
5 changes: 3 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ export interface CircuitReport {

export interface ProgramReport {
// Name of the program package
name: string;
package_name: string;
functions: CircuitReport[];
}

export interface ContractReport {
name: string;
functions: ProgramReport[];
// TODO(https://github.com/noir-lang/noir/issues/4720): Settle on how to display contract functions with non-inlined Acir calls
functions: CircuitReport[];
}

export interface WorkspaceReport {
Expand Down
1 change: 1 addition & 0 deletions tests/mocks/full_gas_report.json

Large diffs are not rendered by default.

166 changes: 93 additions & 73 deletions tests/mocks/gas_report.1.json
Original file line number Diff line number Diff line change
@@ -1,86 +1,106 @@
{
"programs": [
{
"name": "a",
{
"package_name": "a",
"functions": [
{
"name": "main",
"acir_opcodes": 1,
"circuit_size": 7
},
{
"name": "b",
}
]
},
{
"package_name": "b",
"functions": [
{
"name": "main",
"acir_opcodes": 4,
"circuit_size": 8
},
{
"name": "c",
}
]
},
{
"package_name": "c",
"functions": [
{
"name": "main",
"acir_opcodes": 4,
"circuit_size": 8
},
{
"name": "d",
}
]
},
{
"package_name": "d",
"functions": [
{
"name": "main",
"acir_opcodes": 4,
"circuit_size": 8
}
}
]
}
],
"contracts": [
{
"name": "a",
"functions": [
{
"name": "a",
"acir_opcodes": 1,
"circuit_size": 7
},
{
"name": "b",
"acir_opcodes": 4,
"circuit_size": 8
},
{
"name": "c",
"acir_opcodes": 500,
"circuit_size": 1000
},
{
"name": "d",
"acir_opcodes": 500,
"circuit_size": 1000
},
{
"name": "e",
"acir_opcodes": 50,
"circuit_size": 100
},
{
"name": "f",
"acir_opcodes": 50,
"circuit_size": 100
},
{
"name": "g",
"acir_opcodes": 50,
"circuit_size": 100
},
{
"name": "h",
"acir_opcodes": 50,
"circuit_size": 100
}
]
},
{
"name": "b",
"functions": [
{
"name": "a",
"acir_opcodes": 1,
"circuit_size": 7
},
{
"name": "b",
"acir_opcodes": 4,
"circuit_size": 8
}
]
}
{
"name": "a",
"functions": [
{
"name": "a",
"acir_opcodes": 1,
"circuit_size": 7
},
{
"name": "b",
"acir_opcodes": 4,
"circuit_size": 8
},
{
"name": "c",
"acir_opcodes": 500,
"circuit_size": 1000
},
{
"name": "d",
"acir_opcodes": 500,
"circuit_size": 1000
},
{
"name": "e",
"acir_opcodes": 50,
"circuit_size": 100
},
{
"name": "f",
"acir_opcodes": 50,
"circuit_size": 100
},
{
"name": "g",
"acir_opcodes": 50,
"circuit_size": 100
},
{
"name": "h",
"acir_opcodes": 50,
"circuit_size": 100
}
]
},
{
"name": "b",
"functions": [
{
"name": "a",
"acir_opcodes": 1,
"circuit_size": 7
},
{
"name": "b",
"acir_opcodes": 4,
"circuit_size": 8
}
]
}
]
}
}
Loading

0 comments on commit d4cdc54

Please sign in to comment.