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

feat: implement quadtree #23

Closed
wants to merge 15 commits into from
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ jobs:
components: clippy

- name: Clippy check
run: cargo clippy --workspace --tests --examples --all-features
run: cargo clippy --workspace --tests --examples --all-features -- -D warnings


39 changes: 28 additions & 11 deletions Cargo.lock

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

9 changes: 3 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ resolver = "2"

members = [
"server",
"quadtree",
"chunk",
"generator-build",
"generator"
"generator",
]

[profile.dev]
Expand All @@ -18,19 +19,15 @@ opt-level = 1
opt-level = 3

[profile.release]
#debug = true
lto = "fat"
codegen-units = 1
#strip = false
#panic = "abort"

[profile.bench]
#debug = true
lto = "fat"
codegen-units = 1
#panic = "abort"

[workspace.dependencies]
chunk = { path = "chunk" }
generator-build = { path = "generator-build" }
generator = { path = "generator" }
quadtree = { path = "quadtree" }
3 changes: 2 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ skip = [
"event-listener",
"base64",
"regex-syntax",
"regex-automata"
"regex-automata",
"glam"
#{ crate = "[email protected]", reason = "you can specify a reason why it can't be updated/removed" },
]
# Similarly to `skip` allows you to skip certain crates during duplicate
Expand Down
4 changes: 2 additions & 2 deletions generator-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ publish = false
anyhow = "1.0.81"
heck = "0.5.0"
itertools = "0.12.1"
prettyplease = "0.2.16"
prettyplease = "0.2.17"
proc-macro2 = "1.0.79"
quote = "1.0.35"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.114"
serde_json = "1.0.115"
syn = "2.0.55"

[lints.rust]
Expand Down
1 change: 1 addition & 0 deletions quadtree/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
31 changes: 31 additions & 0 deletions quadtree/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
[package]
name = "quadtree"
version = "0.1.0"
edition = "2021"
authors = ["Andrew Gazelka <[email protected]>"]
readme = "README.md"
publish = false

[dependencies]
glam = "0.27.0"
itertools = "0.12.1"
num-traits = "0.2.18"

[dev-dependencies]
divan = "0.1.14"
rand = "0.8.5"

[[bench]]
name = "rebuild"
harness = false

[lints.clippy]
complexity = "deny"

nursery = { level = "deny", priority = -1 }
redundant_pub_crate = "allow"

pedantic = "deny"
perf = "deny"
style = "deny"
suspicious = "deny"
Empty file added quadtree/README.md
Empty file.
121 changes: 121 additions & 0 deletions quadtree/benches/rebuild.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
use divan::{AllocProfiler, Bencher};
use quadtree::rebuild::MoveElement;
use rand::prelude::SliceRandom;

#[global_allocator]
static ALLOC: AllocProfiler = AllocProfiler::system();

fn main() {
divan::main();
}

// Register a `fibonacci` function and benchmark it over multiple cases.

//
const LENS: &[usize] = &[64, 512, 4096, 32768, 262_144];

#[divan::bench(
args = LENS,
)]
fn rebuild_single(bencher: Bencher, len: usize) {
let v = (0..len).collect::<Vec<_>>();

let changes = vec![quadtree::rebuild::MoveElement {
remove_from_idx: 1,
insert_to_idx: 3,
}];

bencher.bench(|| {
quadtree::rebuild::apply_vec(&v, &changes, &mut [0, 1, 2, 3, 4]);
});
}

#[divan::bench(
args = LENS,
)]
fn rebuild_every(bencher: Bencher, len: usize) {
let v = (0..len).collect::<Vec<_>>();

let arr = 0..len;

// shuffle the array
let mut arr = arr.collect::<Vec<_>>();
arr.shuffle(&mut rand::thread_rng());

let changes = arr
.iter()
.enumerate()
.map(|(i, &x)| quadtree::rebuild::MoveElement {
remove_from_idx: i,
insert_to_idx: x,
})
.collect::<Vec<_>>();

bencher.counter(len).bench(|| {
quadtree::rebuild::apply_vec(&v, &changes, &mut [0, 1, 2, 3, 4]);
});
}

#[divan::bench(
args = LENS,
)]
fn rebuild_262144(bencher: Bencher, len: usize) {
const LEN: usize = 262_144;
let v = (0..LEN).collect::<Vec<_>>();

let arr = 0..len;

// shuffle the array
let mut arr = arr.collect::<Vec<_>>();
arr.shuffle(&mut rand::thread_rng());

let changes = arr
.iter()
.enumerate()
.map(|(i, &x)| quadtree::rebuild::MoveElement {
remove_from_idx: i,
insert_to_idx: x,
})
.collect::<Vec<_>>();

bencher.bench(|| {
quadtree::rebuild::apply_vec(&v, &changes, &mut [0, 1, 2, 3, 4]);
});
}

#[divan::bench(
args = [64, 512, 4096],
)]
fn rebuild_262144_naive(bencher: Bencher, len: usize) {
const LEN: usize = 262_144;
let v = (0..LEN).collect::<Vec<_>>();

let arr = 0..len;

// shuffle the array
let mut arr = arr.collect::<Vec<_>>();
arr.shuffle(&mut rand::thread_rng());

let changes = arr
.iter()
.enumerate()
.map(|(i, &x)| quadtree::rebuild::MoveElement {
remove_from_idx: i,
insert_to_idx: x,
})
.collect::<Vec<_>>();

bencher.bench(|| {
let mut v = v.clone();

for &MoveElement {
remove_from_idx,
insert_to_idx,
} in &changes
{
let elem = v[remove_from_idx];
v.remove(remove_from_idx);
v.insert(insert_to_idx, elem);
}
});
}
21 changes: 21 additions & 0 deletions quadtree/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
combine_control_expr = true
comment_width = 100 # https://lkml.org/lkml/2020/5/29/1038
condense_wildcard_suffixes = true
control_brace_style = "AlwaysSameLine"
edition = "2021"
format_code_in_doc_comments = true
format_macro_bodies = true
format_macro_matchers = true
format_strings = true
group_imports = "StdExternalCrate"
imports_granularity = "Crate"
merge_derives = false
newline_style = "Unix"
normalize_comments = true
normalize_doc_attributes = true
overflow_delimited_expr = true
reorder_impl_items = true
reorder_imports = true
unstable_features = true
wrap_comments = true

Loading
Loading