chore: move to crates folder

This commit is contained in:
Alexander Medvedev committed 2026-08-06 12:56:40 +02:00
1 parent 5d10c0d8a8
commit cb3660bcd2
3393 files changed
+1270 -741

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
use criterion::{Criterion, criterion_group, criterion_main};
use pumpkin_data::{
chunk_gen_settings::GenerationSettings, dimension::Dimension,
noise_router::OVERWORLD_BASE_NOISE_ROUTER,
};
use pumpkin_world::{
GlobalRandomConfig, ProtoNoiseRouters, bench_create_and_populate_biome,
bench_create_and_populate_noise, bench_create_and_populate_noise_with_surface,
generation::proto_chunk::TerrainCache,
};
fn bench_terrain_gen(c: &mut Criterion) {
let seed = 0;
let random_config = GlobalRandomConfig::new(seed, false);
let base_router = ProtoNoiseRouters::generate(&OVERWORLD_BASE_NOISE_ROUTER, &random_config);
let surface_config = GenerationSettings::from_dimension(&Dimension::OVERWORLD);
let terrain_cache = TerrainCache::from_random(&random_config);
let default_state = surface_config.default_block;
c.bench_function("overworld biome", |b| {
b.iter(|| {
bench_create_and_populate_biome(
&base_router,
&random_config,
surface_config,
&terrain_cache,
default_state,
);
});
});
c.bench_function("overworld noise", |b| {
b.iter(|| {
bench_create_and_populate_noise(
&base_router,
&random_config,
surface_config,
&terrain_cache,
default_state,
);
});
});
c.bench_function("overworld surface", |b| {
b.iter(|| {
bench_create_and_populate_noise_with_surface(
&base_router,
&random_config,
surface_config,
&terrain_cache,
default_state,
);
});
});
}
criterion_group!(benches, bench_terrain_gen);
criterion_main!(benches);
+360
View File
@@ -0,0 +1,360 @@
use criterion::{BatchSize, Criterion, criterion_group, criterion_main};
use pumpkin_config::lighting::LightingEngineConfig;
use pumpkin_data::BlockStateId;
use pumpkin_data::dimension::Dimension;
use pumpkin_util::world_seed::Seed;
use pumpkin_world::ProtoChunk;
use pumpkin_world::chunk_system::{Cache, Chunk, StagedChunkEnum, generate_single_chunk};
use pumpkin_world::generation::generator::WorldGenerator;
use pumpkin_world::generation::get_world_gen;
use pumpkin_world::world::WorldPortalExt;
use std::hint::black_box;
use std::sync::Arc;
const SEED: Seed = Seed(42);
struct BlockRegistry;
impl WorldPortalExt for BlockRegistry {
fn can_place_at(
&self,
_block: &pumpkin_data::Block,
_state: &pumpkin_data::BlockState,
_block_accessor: &dyn pumpkin_world::world::BlockAccessor,
_block_pos: &pumpkin_util::math::position::BlockPos,
) -> bool {
true
}
fn mirror(
&self,
block: &pumpkin_data::Block,
state_id: BlockStateId,
mirror: pumpkin_data::Mirror,
) -> &'static pumpkin_data::BlockState {
block.mirror(state_id, mirror)
}
fn rotate(
&self,
block: &pumpkin_data::Block,
state_id: BlockStateId,
rotation: pumpkin_data::Rotation,
) -> &'static pumpkin_data::BlockState {
block.rotate(state_id, rotation)
}
fn spawn_mobs_for_chunk_generation(
&self,
_cache: &mut dyn pumpkin_world::generation::proto_chunk::GenerationCache,
_biome: &'static pumpkin_data::chunk::Biome,
_chunk_x: i32,
_chunk_z: i32,
) {
}
}
fn make_world_gen() -> Box<WorldGenerator> {
get_world_gen(SEED, Dimension::OVERWORLD, false, Vec::new(), String::new())
}
fn setup_cache(
target_stage: StagedChunkEnum,
world_gen: &WorldGenerator,
block_registry: &dyn WorldPortalExt,
) -> Cache {
let radius = target_stage.get_direct_radius();
let mut cache = Cache::new(-radius, -radius, radius * 2 + 1);
for dx in -radius..=radius {
for dz in -radius..=radius {
cache
.chunks
.push(Chunk::Proto(Box::new(ProtoChunk::new(dx, dz, world_gen))));
}
}
let pipeline = [
StagedChunkEnum::Biomes,
StagedChunkEnum::StructureStart,
StagedChunkEnum::StructureReferences,
StagedChunkEnum::Noise,
StagedChunkEnum::Surface,
StagedChunkEnum::Carvers,
StagedChunkEnum::Features,
StagedChunkEnum::Lighting,
StagedChunkEnum::Spawn,
];
for stage in pipeline {
if stage as u8 >= target_stage as u8 {
break;
}
cache.advance(
stage,
world_gen,
block_registry,
&LightingEngineConfig::Default,
);
}
cache
}
fn bench_full_chunk_generation(c: &mut Criterion) {
let dimension = Dimension::OVERWORLD;
let world_gen = make_world_gen();
let block_registry = Arc::new(BlockRegistry);
c.bench_function("full_chunk_generation", |b| {
b.iter(|| {
black_box(generate_single_chunk(
&dimension,
0,
&world_gen,
block_registry.as_ref(),
black_box(0),
black_box(0),
StagedChunkEnum::Full,
));
});
});
}
fn bench_biomes_generation(c: &mut Criterion) {
let world_gen = make_world_gen();
let block_registry = Arc::new(BlockRegistry);
c.bench_function("biomes_generation", |b| {
b.iter_batched(
|| setup_cache(StagedChunkEnum::Biomes, &world_gen, block_registry.as_ref()),
|mut cache| {
cache.advance(
StagedChunkEnum::Biomes,
&world_gen,
block_registry.as_ref(),
&LightingEngineConfig::Default,
);
black_box(cache);
},
BatchSize::SmallInput,
);
});
}
fn bench_structure_starts_generation(c: &mut Criterion) {
let world_gen = make_world_gen();
let block_registry = Arc::new(BlockRegistry);
c.bench_function("structure_starts_generation", |b| {
b.iter_batched(
|| {
setup_cache(
StagedChunkEnum::StructureStart,
&world_gen,
block_registry.as_ref(),
)
},
|mut cache| {
cache.advance(
StagedChunkEnum::StructureStart,
&world_gen,
block_registry.as_ref(),
&LightingEngineConfig::Default,
);
black_box(cache);
},
BatchSize::SmallInput,
);
});
}
fn bench_structure_references_generation(c: &mut Criterion) {
let world_gen = make_world_gen();
let block_registry = Arc::new(BlockRegistry);
c.bench_function("structure_references_generation", |b| {
b.iter_batched(
|| {
setup_cache(
StagedChunkEnum::StructureReferences,
&world_gen,
block_registry.as_ref(),
)
},
|mut cache| {
cache.advance(
StagedChunkEnum::StructureReferences,
&world_gen,
block_registry.as_ref(),
&LightingEngineConfig::Default,
);
black_box(cache);
},
BatchSize::SmallInput,
);
});
}
fn bench_noise_generation(c: &mut Criterion) {
let world_gen = make_world_gen();
let block_registry = Arc::new(BlockRegistry);
c.bench_function("noise_generation", |b| {
b.iter_batched(
|| setup_cache(StagedChunkEnum::Noise, &world_gen, block_registry.as_ref()),
|mut cache| {
cache.advance(
StagedChunkEnum::Noise,
&world_gen,
block_registry.as_ref(),
&LightingEngineConfig::Default,
);
black_box(cache);
},
BatchSize::SmallInput,
);
});
}
fn bench_surface_generation(c: &mut Criterion) {
let world_gen = make_world_gen();
let block_registry = Arc::new(BlockRegistry);
c.bench_function("surface_generation", |b| {
b.iter_batched(
|| {
setup_cache(
StagedChunkEnum::Surface,
&world_gen,
block_registry.as_ref(),
)
},
|mut cache| {
cache.advance(
StagedChunkEnum::Surface,
&world_gen,
block_registry.as_ref(),
&LightingEngineConfig::Default,
);
black_box(cache);
},
BatchSize::SmallInput,
);
});
}
fn bench_carvers_generation(c: &mut Criterion) {
let world_gen = make_world_gen();
let block_registry = Arc::new(BlockRegistry);
c.bench_function("carvers_generation", |b| {
b.iter_batched(
|| {
setup_cache(
StagedChunkEnum::Carvers,
&world_gen,
block_registry.as_ref(),
)
},
|mut cache| {
cache.advance(
StagedChunkEnum::Carvers,
&world_gen,
block_registry.as_ref(),
&LightingEngineConfig::Default,
);
black_box(cache);
},
BatchSize::SmallInput,
);
});
}
fn bench_features_generation(c: &mut Criterion) {
let world_gen = make_world_gen();
let block_registry = Arc::new(BlockRegistry);
c.bench_function("features_generation", |b| {
b.iter_batched(
|| {
setup_cache(
StagedChunkEnum::Features,
&world_gen,
block_registry.as_ref(),
)
},
|mut cache| {
cache.advance(
StagedChunkEnum::Features,
&world_gen,
block_registry.as_ref(),
&LightingEngineConfig::Default,
);
black_box(cache);
},
BatchSize::SmallInput,
);
});
}
fn bench_lighting_generation(c: &mut Criterion) {
let world_gen = make_world_gen();
let block_registry = Arc::new(BlockRegistry);
c.bench_function("lighting_generation", |b| {
b.iter_batched(
|| {
setup_cache(
StagedChunkEnum::Lighting,
&world_gen,
block_registry.as_ref(),
)
},
|mut cache| {
cache.advance(
StagedChunkEnum::Lighting,
&world_gen,
block_registry.as_ref(),
&LightingEngineConfig::Default,
);
black_box(cache);
},
BatchSize::SmallInput,
);
});
}
fn bench_level_chunk_conversion(c: &mut Criterion) {
let world_gen = make_world_gen();
let block_registry = Arc::new(BlockRegistry);
c.bench_function("level_chunk_conversion", |b| {
b.iter_batched(
|| setup_cache(StagedChunkEnum::Full, &world_gen, block_registry.as_ref()),
|mut cache| {
cache.advance(
StagedChunkEnum::Full,
&world_gen,
block_registry.as_ref(),
&LightingEngineConfig::Default,
);
black_box(cache);
},
BatchSize::SmallInput,
);
});
}
criterion_group!(
benches,
bench_full_chunk_generation,
bench_biomes_generation,
bench_structure_starts_generation,
bench_structure_references_generation,
bench_noise_generation,
bench_surface_generation,
bench_carvers_generation,
bench_features_generation,
bench_lighting_generation,
bench_level_chunk_conversion,
);
criterion_main!(benches);
@@ -0,0 +1,118 @@
use criterion::{Criterion, criterion_group, criterion_main};
use pumpkin_data::BlockStateId;
use pumpkin_data::dimension::Dimension;
use pumpkin_util::world_seed::Seed;
use pumpkin_world::chunk_system::{StagedChunkEnum, generate_single_chunk};
use pumpkin_world::generation::get_world_gen;
use pumpkin_world::world::WorldPortalExt;
use std::hint::black_box;
use std::sync::Arc;
use std::time::Instant;
const SEED: Seed = Seed(42);
const THREAD_COUNT: usize = 4;
const GRID_SIZE: i32 = 4;
// Stub portal — allows all block placements, skips mob spawning.
struct BlockRegistry;
impl WorldPortalExt for BlockRegistry {
fn can_place_at(
&self,
_block: &pumpkin_data::Block,
_state: &pumpkin_data::BlockState,
_block_accessor: &dyn pumpkin_world::world::BlockAccessor,
_block_pos: &pumpkin_util::math::position::BlockPos,
) -> bool {
true
}
fn mirror(
&self,
block: &pumpkin_data::Block,
state_id: BlockStateId,
mirror: pumpkin_data::Mirror,
) -> &'static pumpkin_data::BlockState {
block.mirror(state_id, mirror)
}
fn rotate(
&self,
block: &pumpkin_data::Block,
state_id: BlockStateId,
rotation: pumpkin_data::Rotation,
) -> &'static pumpkin_data::BlockState {
block.rotate(state_id, rotation)
}
fn spawn_mobs_for_chunk_generation(
&self,
_cache: &mut dyn pumpkin_world::generation::proto_chunk::GenerationCache,
_biome: &'static pumpkin_data::chunk::Biome,
_chunk_x: i32,
_chunk_z: i32,
) {
}
}
/// Benchmarks the full pipeline for a `GRID_SIZE^2` chunks grid running in parallel
/// across `THREAD_COUNT` rayon threads.
fn bench_concurrent_chunk_generation(c: &mut Criterion) {
let pool = rayon::ThreadPoolBuilder::new()
.num_threads(THREAD_COUNT)
.thread_name(|i| format!("bench-chunk-{i}"))
.build()
.expect("Failed to build rayon thread pool");
let world_gen = Arc::new(get_world_gen(
SEED,
Dimension::OVERWORLD,
false,
Vec::new(),
String::new(),
));
let block_registry = Arc::new(BlockRegistry);
let bench_name = format!(
"concurrent_full_pipeline_{}_chunks_{}_threads",
GRID_SIZE * GRID_SIZE,
THREAD_COUNT
);
c.bench_function(&bench_name, |b| {
b.iter_custom(|iters| {
let mut total = std::time::Duration::ZERO;
for _ in 0..iters {
let wg = world_gen.clone();
let br = block_registry.clone();
let start = Instant::now();
pool.scope(|s| {
for cx in 0..GRID_SIZE {
for cz in 0..GRID_SIZE {
let wg = wg.clone();
let br = br.clone();
s.spawn(move |_| {
black_box(generate_single_chunk(
&Dimension::OVERWORLD,
0,
&wg,
br.as_ref(),
cx,
cz,
StagedChunkEnum::Full,
));
});
}
}
});
total += start.elapsed();
}
total
});
});
}
criterion_group!(benches, bench_concurrent_chunk_generation);
criterion_main!(benches);
+93
View File
@@ -0,0 +1,93 @@
use criterion::{Criterion, criterion_group, criterion_main};
use pumpkin_data::{BlockStateId, dimension::Dimension};
use pumpkin_util::{math::vector2::Vector2, world_seed::Seed};
use pumpkin_world::{
chunk::{ChunkData, format::anvil::SingleChunkDataSerializer},
chunk_system::{Chunk, StagedChunkEnum, generate_single_chunk},
generation::get_world_gen,
world::WorldPortalExt,
};
use std::hint::black_box;
struct BlockRegistry;
impl WorldPortalExt for BlockRegistry {
fn can_place_at(
&self,
_block: &pumpkin_data::Block,
_state: &pumpkin_data::BlockState,
_block_accessor: &dyn pumpkin_world::world::BlockAccessor,
_block_pos: &pumpkin_util::math::position::BlockPos,
) -> bool {
true
}
fn mirror(
&self,
block: &pumpkin_data::Block,
state_id: BlockStateId,
mirror: pumpkin_data::Mirror,
) -> &'static pumpkin_data::BlockState {
block.mirror(state_id, mirror)
}
fn rotate(
&self,
block: &pumpkin_data::Block,
state_id: BlockStateId,
rotation: pumpkin_data::Rotation,
) -> &'static pumpkin_data::BlockState {
block.rotate(state_id, rotation)
}
fn spawn_mobs_for_chunk_generation(
&self,
_cache: &mut dyn pumpkin_world::generation::proto_chunk::GenerationCache,
_biome: &'static pumpkin_data::chunk::Biome,
_chunk_x: i32,
_chunk_z: i32,
) {
}
}
fn bench_chunk_deserialization(c: &mut Criterion) {
let dimension = Dimension::OVERWORLD;
let world_gen = get_world_gen(
Seed(42),
dimension.clone(),
false,
Vec::new(),
String::new(),
);
let chunk = generate_single_chunk(
&dimension,
0,
&world_gen,
&BlockRegistry,
0,
0,
StagedChunkEnum::Full,
);
let Chunk::Level(chunk) = chunk else {
panic!("full generation must return a level chunk");
};
let runtime = tokio::runtime::Builder::new_current_thread()
.build()
.expect("failed to create benchmark runtime");
let bytes = runtime
.block_on(chunk.to_bytes())
.expect("failed to serialize benchmark chunk");
let position = Vector2::new(chunk.x, chunk.z);
c.bench_function("chunk_nbt_deserialization", |b| {
b.iter(|| {
black_box(
ChunkData::from_bytes(black_box(&bytes), position)
.expect("failed to deserialize benchmark chunk"),
);
});
});
}
criterion_group!(benches, bench_chunk_deserialization);
criterion_main!(benches);
@@ -0,0 +1,35 @@
use criterion::{Criterion, criterion_group, criterion_main};
use pumpkin_data::noise_router::OVERWORLD_BASE_NOISE_ROUTER;
use pumpkin_world::generation::{
GlobalRandomConfig,
noise::router::{
chunk_density_function::ChunkNoiseFunctionBuilderOptions,
chunk_noise_router::ChunkNoiseRouter, proto_noise_router::ProtoNoiseRouters,
},
};
use std::hint::black_box;
fn bench_noise_router_creation(c: &mut Criterion) {
let base_routers = &OVERWORLD_BASE_NOISE_ROUTER;
let random_config = GlobalRandomConfig::new(0, false);
let proto_routers = ProtoNoiseRouters::generate(base_routers, &random_config);
let proto_noise_router = proto_routers.noise;
let builder_options =
ChunkNoiseFunctionBuilderOptions::new(4, 8, 4, 4, 0, 0, 3, vec![], vec![], None);
// Benchmarking
c.bench_function("noise_router_creation_with_pooling", |b| {
b.iter(|| {
let router = ChunkNoiseRouter::generate(
black_box(&proto_noise_router),
black_box(&builder_options),
);
black_box(router);
});
});
}
criterion_group!(benches, bench_noise_router_creation);
criterion_main!(benches);