-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from ferrumc-rs/rewrite/anvil
Anvil parser
- Loading branch information
Showing
6 changed files
with
395 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
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,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 |
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,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); |
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,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), | ||
} |
Oops, something went wrong.