-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display difference in tx-cost outputs as a comment on PRs (#1703)
This adds a simple diff calculation to the PR comment, just like the present "Transaction costs" comment we get, but instead a diff between the PR and the master branch. Positive numbers are bad - it means the cost/size/etc got larger with the introduction of the PR. These are coloured black. Negative numbers are good - it means a reduction in size/cost/etc, so these are coloured green. Values that are the same between PR and branch are simply listed as `-`; i.e. unchanged. > [!note] > It seems that some differences are expected _even when nothing relevant has changed_, as in this PR itself. So some care will need to be taken in learning how to interpret these numbers, as we see them develop over furture PRs.
- Loading branch information
Showing
3 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#! /usr/bin/env python | ||
|
||
import pandas as pd | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument("header_file", type=str) | ||
parser.add_argument("old_file", type=str) | ||
parser.add_argument("new_file", type=str) | ||
args = parser.parse_args() | ||
|
||
with open(args.header_file, "r") as f: | ||
headers = [ l[3:].strip() for l in f.readlines() ] | ||
|
||
base = pd.read_html(args.old_file, flavor="html5lib") | ||
branch = pd.read_html(args.new_file, flavor="html5lib") | ||
|
||
def script_size(df): | ||
return df.drop(columns=["Hash"]).set_index("Name") | ||
|
||
def parties(df): | ||
return df.set_index("Parties") | ||
|
||
def utxo(df): | ||
return df.set_index("UTxO") | ||
|
||
def compare_to_md(f, old, new): | ||
# New should be better, so we compare to that. | ||
df = f(new) - f(old) | ||
|
||
# Don't keep what we couldn't compare. | ||
df = df.dropna() | ||
|
||
# Round everything to 2 decimals | ||
df = df.round(2) | ||
|
||
# Add colour | ||
def update_colour(x): | ||
if x == 0: | ||
return "-" | ||
|
||
if type(x) is object: | ||
return x | ||
|
||
if x > 0: | ||
return f"+{x}" | ||
else: | ||
return f"$${{\\color{{green}}{x:.2f}}}$$" | ||
|
||
df = df.map(update_colour) | ||
|
||
return df.to_markdown() | ||
|
||
print("Transaction cost differences") | ||
|
||
# First is the script size | ||
|
||
print(f"## {headers[0]}") | ||
print("") | ||
print( compare_to_md( script_size, base[1], branch[1]) ) | ||
|
||
# Then Init, | ||
print("") | ||
print(f"## {headers[1]}") | ||
print("") | ||
print( compare_to_md(parties, base[2], branch[2]) ) | ||
|
||
# Then Commit is different; it doesn't have a "Parties" column | ||
|
||
print("") | ||
print(f"## {headers[2]}") | ||
print("") | ||
print( compare_to_md(utxo, base[3], branch[3]) ) | ||
|
||
# The remaining are all the same as Init. | ||
for i in range(4, 9 + 1): | ||
print("") | ||
print(f"## {headers[i - 1]}") | ||
print("") | ||
print( compare_to_md(parties, base[i], branch[i]) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters