Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ON HOLD] Rust Analyzer Benchmarking Infrastructure #1766

Draft
wants to merge 19 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
uses: ./.github/actions/setup-env
- uses: radixdlt/criterion-compare-action@update-same-commit
with:
branchName: ${{ github.base_ref }}
branchName: ${{ github.base_ref }}
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,22 @@ jobs:
--max-version 50000 \
--breakpoints 10:91850a10dad5ec6d9a974663e87243b3f3ff8f8b1c0dd74135e8ddd097aa6276,100:8ac9b0caf4daad6f821038f325b215932e90fbabce089ca42bc0330c867aa8f8,1000:6b621e9c7f9674c3d71832aec822b695b0e90010dc6158a18e43fbacf296ef69,500000:7dd4403a757f43f4a885e914b8dc38086fdbaf96082fa90067acf1500075e85d
working-directory: radix-clis

benchmark-autocomplete:
name: "Run Autocomplete Benchmarks"
runs-on: ubuntu-16-cores-selfhosted
permissions:
pull-requests: write
steps:
- uses: RDXWorks-actions/checkout@main
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Run Benchmarks
run: python3 benchmark_autocomplete.py > results.md
- uses: RDXWorks-actions/upload-artifact@main
with:
name: autocomplete-benchmarks
path: results.md
- uses: RDXWorks-actions/actions-comment-pull-request@main
with:
filePath: results.md
26 changes: 19 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ members = [
"scrypto-derive",
"scrypto-test",
"scrypto",
"rust-analyzer-tests",
"radix-clis-common",
]

[workspace.dependencies]
Expand All @@ -66,23 +68,29 @@ scrypto = { version = "1.2.0-dev", path = "./scrypto", default-features = false
scrypto-compiler = { version = "1.2.0-dev", path = "./scrypto-compiler", default-features = false }
scrypto-derive = { version = "1.2.0-dev", path = "./scrypto-derive", default-features = false }
scrypto-test = { version = "1.2.0-dev", path = "./scrypto-test", default-features = false }
radix-clis-common = { version = "1.2.0-dev", path = "./radix-clis-common", default-features = false }

arbitrary = { version = "1.3.0", features = ["derive"] }
automod = { version = "1.0.13" }
bech32 = { version = "0.9.0", default-features = false }
bencher = { version = "0.1.5" }
bincode = { version = "2.0.0-rc.1", default-features = false, features = ["derive"] }
bincode = { version = "2.0.0-rc.1", default-features = false, features = [
"derive",
] }
bitflags = { version = "1.3" }
blake2 = { version = "0.10.6", default-features = false }
blst = { version = "0.3.11", default-features = false, optional = false }
toml = { version = "0.8.12" }
bnum = { version = "0.11.0", default-features = false, features = ["numtraits"] }
cargo_toml = { version = "0.15.3" }
colored = { version = "2.0.0", default-features = false }
const-sha1 = { version = "0.3.0", default-features = false }
criterion = { version = "0.3", features = ["html_reports"] }
crossbeam = { version = "0.8.2" }
ed25519-dalek = { version = "1.0.1", default-features = false, features = ["u64_backend"] }
ethnum = {version = "1.3.2", default-features = false }
ed25519-dalek = { version = "1.0.1", default-features = false, features = [
"u64_backend",
] }
ethnum = { version = "1.3.2", default-features = false }
fixedstr = { version = "0.2.9" }
hashbrown = { version = "0.13.2" }
hex = { version = "0.4.3", default-features = false }
Expand All @@ -102,15 +110,19 @@ perfcnt = { version = "0.8.0" }
plotters = { version = "0.3.4" }
proc-macro2 = { version = "1.0.38" }
quote = { version = "1.0.18" }
radix-wasm-instrument = { version = "1.0.0", default-features = false, features = ["ignore_custom_section"]}
radix-wasmi = { version = "1.0.0" }
radix-wasm-instrument = { version = "1.0.0", default-features = false, features = [
"ignore_custom_section",
] }
radix-wasmi = { version = "1.0.0" }
rand = { version = "0.8.5" }
rand_chacha = { version = "0.3.1" }
rayon = { version = "1.5.3" }
rayon = { version = "1.5.3" }
regex = { version = "=1.9.3", default-features = false, features = [] }
rocksdb = { version = "0.21.0" }
rug = { version = "1.18" }
secp256k1 = { version = "0.28.0", default-features = false, features = ["recovery"] }
secp256k1 = { version = "0.28.0", default-features = false, features = [
"recovery",
] }
serde = { version = "1.0.144", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.105" }
sha3 = { version = "0.10.8", default-features = false, optional = false }
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ ADD sbor /app/sbor
ADD sbor-derive /app/sbor-derive
ADD sbor-derive-common /app/sbor-derive-common
ADD scrypto-compiler /app/scrypto-compiler
ADD radix-clis-common /app/radix-clis-common

# Copy radix-clis crate
ADD radix-clis /app/radix-clis
Expand Down
84 changes: 84 additions & 0 deletions benchmark_autocomplete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import re
import os
import subprocess
from typing import cast, BinaryIO, TypedDict


SCRIPT_PATH: str = os.path.dirname(os.path.realpath(__file__))


def main() -> None:
# The path to the workspace manifest file
workspace_manifest_file: str = os.path.abspath(
os.path.join(SCRIPT_PATH, "Cargo.toml")
)

# Listing all of the Rust Analyzer autocomplete tests to run all of them.
list_tests_output: bytes = cast(
BinaryIO,
subprocess.Popen(
[
"cargo",
"test",
"--manifest-path",
workspace_manifest_file,
"--package",
"rust-analyzer-tests",
"--test",
"autocomplete",
"--",
"--list",
"--format=terse",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).stdout,
).read()

# Extract all of the test names from the string.
test_names: list[str] = re.findall(r"(.*)?: test", list_tests_output.decode())

# Run each test and record the time the autocompletion took.
test_results: list[tuple[str, int]] = []
for test_name in test_names:
# Run the test
test_run_output: bytes = cast(
BinaryIO,
subprocess.Popen(
[
"cargo",
"test",
"--release",
"--manifest-path",
workspace_manifest_file,
"--package",
"rust-analyzer-tests",
"--test",
"autocomplete",
"--",
test_name,
"--exact",
"--nocapture",
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
).stdout,
).read()

# Find the amount of time it took to run the benchmark
duration: int = int(
re.findall(r"Autocomplete took: (\d+)ms", test_run_output.decode())[0]
)

# Insert to the list
test_results.append((test_name, duration))

# Output the results as a markdown table to stdout
markdown_table: str = "## Autocomplete Benchmark Results\n| Test Name | Autocomplete (ms) |\n| -- | -- |\n"
for (test_name, duration) in test_results:
markdown_table += f"| `{test_name}` | {duration} |\n"
print(markdown_table)


if __name__ == "__main__":
main()
13 changes: 13 additions & 0 deletions radix-clis-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "radix-clis-common"
version = "1.2.0-dev"
edition = "2021"
description = "Shared logic of the Radix CLIs."
readme = "README.md"
license-file = "../LICENSE"
repository = "https://github.com/radixdlt/radixdlt-scrypto"

# Ref: https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
[lib]
doctest = false
bench = false
3 changes: 3 additions & 0 deletions radix-clis-common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `radix-clis-common`

Shared logic of the Radix CLIs.
1 change: 1 addition & 0 deletions radix-clis-common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod package;
100 changes: 100 additions & 0 deletions radix-clis-common/src/package.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
use std::path::*;

pub fn new_package(
package_name: &str,
path: Option<PathBuf>,
local: bool,
) -> Result<(), PackageError> {
let wasm_name = package_name.replace('-', "_");
let path = path.clone().unwrap_or(PathBuf::from(package_name));
let simulator_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let (
sbor,
scrypto,
transaction,
radix_engine,
radix_engine_interface,
scrypto_test,
optional_scrypto_test,
) = if local {
let scrypto_dir = simulator_dir
.parent()
.unwrap()
.to_string_lossy()
.replace('\\', "/");
(
format!("{{ path = \"{}/sbor\" }}", scrypto_dir),
format!("{{ path = \"{}/scrypto\" }}", scrypto_dir),
format!("{{ path = \"{}/transaction\" }}", scrypto_dir),
format!("{{ path = \"{}/radix-engine\" }}", scrypto_dir),
format!("{{ path = \"{}/radix-engine-interface\" }}", scrypto_dir),
format!("{{ path = \"{}/scrypto-test\" }}", scrypto_dir),
format!(
"{{ path = \"{}/scrypto-test\", optional = true }}",
scrypto_dir
),
)
} else {
let s = format!(
"{{ git = \"https://github.com/radixdlt/radixdlt-scrypto\", tag = \"v{}\" }}",
env!("CARGO_PKG_VERSION")
);
(s.clone(), s.clone(), s.clone(), s.clone(), s.clone(), s, format!(
"{{ git = \"https://github.com/radixdlt/radixdlt-scrypto\", tag = \"v{}\", optional = true }}",
env!("CARGO_PKG_VERSION")
))
};

if path.exists() {
Err(PackageError::PackageAlreadyExists)
} else {
std::fs::create_dir_all(child_of(&path, "src")).map_err(PackageError::IOError)?;
std::fs::create_dir_all(child_of(&path, "tests")).map_err(PackageError::IOError)?;

std::fs::write(
child_of(&path, "Cargo.toml"),
include_str!("../assets/template/Cargo.toml_template")
.replace("${package_name}", package_name)
.replace("${sbor}", &sbor)
.replace("${scrypto}", &scrypto)
.replace("${transaction}", &transaction)
.replace("${radix-engine}", &radix_engine)
.replace("${radix-engine-interface}", &radix_engine_interface)
.replace("${scrypto-test}", &scrypto_test)
.replace("${optional-scrypto-test}", &optional_scrypto_test),
)
.map_err(PackageError::IOError)?;

std::fs::write(
child_of(&path, ".gitignore"),
include_str!("../assets/template/.gitignore"),
)
.map_err(PackageError::IOError)?;

std::fs::write(
child_of(&child_of(&path, "src"), "lib.rs"),
include_str!("../assets/template/src/lib.rs"),
)
.map_err(PackageError::IOError)?;

std::fs::write(
child_of(&child_of(&path, "tests"), "lib.rs"),
include_str!("../assets/template/tests/lib.rs").replace("${wasm_name}", &wasm_name),
)
.map_err(PackageError::IOError)?;

Ok(())
}
}

fn child_of(path: &PathBuf, name: &str) -> PathBuf {
let mut p = path.clone();
p.push(name);
p
}

#[derive(Debug)]
pub enum PackageError {
PackageAlreadyExists,
IOError(std::io::Error),
}
5 changes: 5 additions & 0 deletions radix-clis/Cargo.lock

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

1 change: 1 addition & 0 deletions radix-clis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ radix-substate-store-queries = { version = "1.2.0-dev", path = "../radix-substat
radix-transactions = { version = "1.2.0-dev", path = "../radix-transactions" }
sbor = { version = "1.2.0-dev", path = "../sbor" }
scrypto-compiler = { version = "1.2.0-dev", path = "../scrypto-compiler" }
radix-clis-common = { version = "1.2.0-dev", path = "../radix-clis-common" }

flate2 = { version = "1.0.27" }
tar = { version = "0.4.40" }
Expand Down
Loading
Loading