Skip to content

Commit

Permalink
Merge pull request #100 from ferrumc-rs/rewrite/anvil
Browse files Browse the repository at this point in the history
Anvil parser
  • Loading branch information
Sweattypalms authored Oct 29, 2024
2 parents 80c1a7c + aeff844 commit f852606
Show file tree
Hide file tree
Showing 6 changed files with 395 additions and 4 deletions.
Binary file added .etc/r.0.0.mca
Binary file not shown.
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ members = [
"src/lib/utils", "src/lib/utils/logging", "src/lib/utils/profiling", "src/lib/utils/general_purpose",
"src/lib/world",
"src/lib/derive_macros",
"src/lib/adapters/nbt",
"src/lib/adapters/mca",
"src/tests",
"src/lib/adapters/nbt", "src/lib/adapters/mca",
"src/tests", "src/lib/adapters/anvil",
]

#================== Lints ==================#
Expand Down Expand Up @@ -142,10 +141,13 @@ ctor = "0.2.8"
libflate = "2.1.0"
flate2 = { version = "1.0.33", features = ["zlib"], default-features = false }
zstd = { version = "0.13.2" }
brotli = "6.0.0"
brotli = "7.0.0"
lzzzz = "1.1.0"
yazi = "0.2.0"

# I/O
tempfile = "3.12.0"
memmap2 = "0.9.5"

# Benchmarking
criterion = { version = "0.5.1", features = ["html_reports"] }
27 changes: 27 additions & 0 deletions src/lib/adapters/anvil/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
name = "anvil"
version = "0.1.0"
edition = "2021"

[dependencies]
thiserror = { workspace = true }
memmap2 = { workspace = true}
ferrumc-utils = { workspace = true}
flate2 = { workspace = true}
yazi = { workspace = true}
lzzzz = { workspace = true}
tracing = { workspace = true}
rayon = { workspace = true}

[dev-dependencies]
fastanvil = "0.31.0"
criterion = { workspace = true }
ferrumc-logging = { workspace = true }

[lints]
workspace = true

[[bench]]
name = "anvil"
path = "benches/anvil.rs"
harness = false
72 changes: 72 additions & 0 deletions src/lib/adapters/anvil/benches/anvil.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
use std::fs::File;
use std::path::PathBuf;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use anvil::load_anvil_file;
use ferrumc_utils::root;
use rayon::prelude::*;
use fastanvil::Region;

fn criterion_benchmark(c: &mut Criterion) {
let mut read_all_group = c.benchmark_group("Read All");

read_all_group.bench_function("FerrumC Rayon", |b| {
b.iter(|| {
let file_path = PathBuf::from(root!(".etc/r.0.0.mca"));
let loaded_file = load_anvil_file(file_path).unwrap();
let locations = loaded_file.get_locations();
locations.chunks(96).par_bridge().for_each(|chunk| {
chunk.iter().for_each(|location| {
black_box(loaded_file.get_chunk_from_location(*location));
});
});
});
});

read_all_group.bench_function("FerrumC", |b| {
b.iter(|| {
let file_path = PathBuf::from(root!(".etc/r.0.0.mca"));
let loaded_file = load_anvil_file(file_path).unwrap();
let locations = loaded_file.get_locations();
locations.iter().for_each(|location| {
black_box(loaded_file.get_chunk_from_location(*location));
});
});
});

read_all_group.bench_function("FastAnvil", |b| {
b.iter(|| {
let file = File::open(root!(".etc/r.0.0.mca")).unwrap();
let mut region = Region::from_stream(file).unwrap();
region.iter().for_each(|chunk| {
black_box(chunk.unwrap().data);
});
});
});

read_all_group.finish();

let mut read_one_group = c.benchmark_group("Read One");

read_one_group.bench_function("FerrumC", |b| {
b.iter(|| {
let file_path = PathBuf::from(root!(".etc/r.0.0.mca"));
let loaded_file = load_anvil_file(file_path).unwrap();
black_box(loaded_file.get_chunk(0, 0));
});
});

read_one_group.bench_function("FastAnvil", |b| {
b.iter(|| {
let file = File::open(root!(".etc/r.0.0.mca")).unwrap();
let mut region = Region::from_stream(file).unwrap();
black_box(region.read_chunk(0, 0).unwrap());
});
});

read_one_group.finish();
}



criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);
14 changes: 14 additions & 0 deletions src/lib/adapters/anvil/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::path::PathBuf;
use thiserror::Error;

#[derive(Debug, Error)]
pub enum AnvilError {
#[error("File not found: {0}")]
FileNotFound(PathBuf),
#[error("Invalid tables: {0}")]
InvalidTables(PathBuf),
#[error("Unable to read file {0}: {1}")]
UnableToReadFile(PathBuf, std::io::Error),
#[error("Unable to map file {0}: {1}")]
UnableToMapFile(PathBuf, std::io::Error),
}
Loading

0 comments on commit f852606

Please sign in to comment.