Skip to content

Commit

Permalink
Repl startup performance improvements (#133)
Browse files Browse the repository at this point in the history
REPL startup time should be improved by roughly 50%. Hashmap and hashset operations will re use allocations when possible.
  • Loading branch information
mattwparas authored Jan 15, 2024
1 parent 2e14129 commit 4cf5e15
Show file tree
Hide file tree
Showing 72 changed files with 4,536 additions and 2,469 deletions.
49 changes: 38 additions & 11 deletions Cargo.lock

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

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description = "Steel repl and command line interface"
include = ["/src/**/*", "/Cargo.toml", "/README.md", "LICENSE*"]

[workspace.package]
version = "0.5.0"
version = "0.6.0"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
Expand All @@ -19,17 +19,17 @@ path = "src/main.rs"

[workspace.dependencies]
# This has to line up with the workspace version above
steel-core = { path = "./crates/steel-core", version = "0.5.0", features = ["web", "sqlite", "dylibs", "markdown"] }
steel-core = { path = "./crates/steel-core", version = "0.6.0", features = ["web", "sqlite", "dylibs", "markdown", "stacker"] }

[dependencies]
once_cell = "1.17.0"
steel-core = { workspace = true }
steel-derive = { path = "./crates/steel-derive", version = "0.4.0"}
steel-repl = { path = "./crates/steel-repl", version = "0.5.0" }
steel-derive = { path = "./crates/steel-derive", version = "0.5.0"}
steel-repl = { path = "./crates/steel-repl", version = "0.6.0" }
env_logger = "0.10.0"
log = "0.4.17"
clap = { version = "4.1.4", features = ["derive"] }
steel-doc = { path = "./crates/steel-doc", version = "0.5.0"}
steel-doc = { path = "./crates/steel-doc", version = "0.6.0"}

[dev-dependencies]
serde = { version = "1.0.152", features = ["derive"] }
Expand All @@ -41,6 +41,6 @@ members = [
]

[profile.release]
# debug = false
debug = true
debug = false
# debug = true
lto = true
12 changes: 6 additions & 6 deletions crates/cargo-steel-lib/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ fn package_contains_dependency_on_steel(packages: &[Package]) -> Option<&Package
packages.iter().find(|x| x.name == "steel-core")
}

/*
TODO:
- Desired output directory / do not copy to native automatically
- Specify target architecture
*/

fn main() -> Result<(), Box<dyn Error>> {
// let build_target = Command::new("cargo")
// .arg("build")
Expand All @@ -21,10 +27,6 @@ fn main() -> Result<(), Box<dyn Error>> {

let metadata = MetadataCommand::new().exec()?;

// println!("{:#?}", metadata?.root_package());

// let package_name = metadata?.root_package().expect("Missing cargo toml!").

let package = match metadata.root_package() {
Some(p) => p,
None => return Err("cargo steel-lib must be run from within a crate".into()),
Expand Down Expand Up @@ -63,7 +65,6 @@ fn main() -> Result<(), Box<dyn Error>> {

if last.target.kind == ["cdylib"] {
println!("Found a cdylib!");
// println!("{:#?}", last);

for file in last.filenames {
let filename = file.file_name().unwrap();
Expand All @@ -78,7 +79,6 @@ fn main() -> Result<(), Box<dyn Error>> {
}
} else if last.target.kind == ["dylib"] {
println!("Found a dylib!");
// println!("{:#?}", last);

for file in last.filenames {
let filename = file.file_name().unwrap();
Expand Down
15 changes: 10 additions & 5 deletions crates/steel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ serde = { version = "1.0.193", features = ["derive", "rc"] }
serde_derive = "1.0.193"
bincode = "1.3.3"
pretty = "0.12.1"
im-lists = "0.7.0"
im-lists = "0.7.1"

quickscope = "0.2.0"
lasso = { version = "0.7.2", features = ["multi-threaded", "serialize"] }
once_cell = "1.18.0"
fxhash = "0.2.1"
# lazy_static = "1.4.0"
steel-gen = { path = "../steel-gen", version = "0.2.0" }
steel-parser = { path = "../steel-parser", version = "0.4.0" }
steel-derive = { path = "../steel-derive", version = "0.4.0" }
steel-parser = { path = "../steel-parser", version = "0.6.0" }
steel-derive = { path = "../steel-derive", version = "0.5.0" }
chrono = { version = "0.4.23", default-features = false, features = ["std", "clock"] }
weak-table = "0.3.2"
# TODO: Consider whether rand needs to be here
Expand All @@ -45,7 +46,7 @@ which = "4.4.0"
radix_fmt = "1.0.0"

# For structs
smallvec = { version = "1.10.0", optional = true }
smallvec = { version = "1.10.0" }

# Pretty printing documentation
termimad = { version = "0.21.0", optional = true }
Expand All @@ -64,6 +65,8 @@ reqwest = { version = "0.11.14", features = ["blocking", "json"], optional = tru
url = { version = "2.3.1", optional = true }
anyhow = { version = "1", optional = true }

stacker = { version = "0.1.15", optional = true }

[dev-dependencies]
proptest = "1.1.0"
criterion = "0.5.1"
Expand All @@ -84,8 +87,10 @@ unsafe-internals = []
anyhow = ["dep:anyhow"]
dylibs = ["dep:abi_stable", "dep:async-ffi"]
markdown = ["dep:termimad"]
smallvec = ["dep:smallvec"]
smallvec = []
without-drop-protection = []
stacker = ["dep:stacker"]


[[bench]]
name = "my_benchmark"
Expand Down
7 changes: 6 additions & 1 deletion crates/steel-core/benches/my_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ use criterion::{black_box, criterion_group, criterion_main, Criterion};
use steel::stdlib::PRELUDE;
use steel::steel_vm::{engine::Engine, register_fn::RegisterFn};

fn benchmark_template(c: &mut Criterion, name: &str, script: &str, warmup: &str) {
fn benchmark_template(
c: &mut Criterion,
name: &'static str,
script: &'static str,
warmup: &'static str,
) {
let mut vm = Engine::new();
vm.compile_and_run_raw_program(PRELUDE).unwrap();
vm.compile_and_run_raw_program(black_box(warmup)).unwrap();
Expand Down
3 changes: 2 additions & 1 deletion crates/steel-core/src/compiler/code_gen.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::atomic::AtomicUsize;

use smallvec::SmallVec;
use steel_parser::tokens::MaybeBigInt;

use crate::{
Expand Down Expand Up @@ -879,7 +880,7 @@ impl<'a> VisitorMut for CodeGenerator<'a> {
.arguments
.values()
.filter(|x| x.captured && x.mutated)
.collect::<Vec<_>>();
.collect::<SmallVec<[_; 8]>>();

heap_allocated_arguments.sort_by_key(|x| x.stack_offset);

Expand Down
Loading

0 comments on commit 4cf5e15

Please sign in to comment.