-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve gcloud load times (#28)
* feat: flexbuffer gcloud format * chore: allow bugfix version update * docs: credits * refactor: codec abstraction and benchmarks * chore: correct workflow name * fix: tests and bench * chore: trigger bench on PR synchronize * fix: disable libtest #[bench] * fix: failure due to main comparison * feat: bincode2 + flate2 format * refactor: optional ply loading
- Loading branch information
Showing
17 changed files
with
322 additions
and
94 deletions.
There are no files selected for viewing
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,41 @@ | ||
name: bench | ||
|
||
on: | ||
pull_request: | ||
types: [ labeled, synchronize ] | ||
branches: [ "main" ] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
RUST_BACKTRACE: 1 | ||
|
||
jobs: | ||
bench: | ||
if: contains(github.event.pull_request.labels.*.name, 'bench') | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [windows-latest, macos-latest] | ||
|
||
runs-on: ${{ matrix.os }} | ||
timeout-minutes: 120 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cargo/bin/ | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
target/ | ||
key: ${{ runner.os }}-cargo-build-stable-${{ hashFiles('**/Cargo.toml') }} | ||
|
||
- name: io benchmark | ||
uses: boa-dev/[email protected] | ||
with: | ||
benchName: "io" | ||
branchName: ${{ github.base_ref }} | ||
token: ${{ secrets.GITHUB_TOKEN }} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use criterion::{ | ||
BenchmarkId, | ||
criterion_group, | ||
criterion_main, | ||
Criterion, | ||
Throughput, | ||
}; | ||
|
||
use bevy_gaussian_splatting::{ | ||
Gaussian, | ||
GaussianCloud, | ||
io::codec::GaussianCloudCodec, | ||
random_gaussians, | ||
}; | ||
|
||
|
||
const GAUSSIAN_COUNTS: [usize; 4] = [ | ||
1000, | ||
10000, | ||
84_348, | ||
1_244_819, | ||
// 6_131_954, | ||
]; | ||
|
||
fn gaussian_cloud_decode_benchmark(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("encode gaussian clouds"); | ||
for count in GAUSSIAN_COUNTS.iter() { | ||
group.throughput(Throughput::Bytes(*count as u64 * std::mem::size_of::<Gaussian>() as u64)); | ||
group.bench_with_input( | ||
BenchmarkId::new("decode", count), | ||
&count, | ||
|b, &count| { | ||
let gaussians = random_gaussians(*count); | ||
let bytes = gaussians.encode(); | ||
|
||
b.iter(|| GaussianCloud::decode(bytes.as_slice())); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
criterion_group!{ | ||
name = io_benches; | ||
config = Criterion::default().sample_size(10); | ||
targets = gaussian_cloud_decode_benchmark | ||
} | ||
criterion_main!(io_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
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,6 @@ | ||
|
||
// TODO: support streamed codecs | ||
pub trait GaussianCloudCodec { | ||
fn encode(&self) -> Vec<u8>; | ||
fn decode(data: &[u8]) -> Self; | ||
} |
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,35 @@ | ||
use bincode2::{ | ||
deserialize_from, | ||
serialize_into, | ||
}; | ||
use flate2::{ | ||
Compression, | ||
read::GzDecoder, | ||
write::GzEncoder, | ||
}; | ||
|
||
use crate::{ | ||
gaussian::GaussianCloud, | ||
io::codec::GaussianCloudCodec, | ||
}; | ||
|
||
|
||
impl GaussianCloudCodec for GaussianCloud { | ||
fn encode(&self) -> Vec<u8> { | ||
let mut output = Vec::new(); | ||
|
||
{ | ||
let mut gz_encoder = GzEncoder::new(&mut output, Compression::default()); | ||
serialize_into(&mut gz_encoder, &self).expect("failed to encode cloud"); | ||
} | ||
|
||
output | ||
} | ||
|
||
fn decode(data: &[u8]) -> Self { | ||
let decompressed = GzDecoder::new(data); | ||
let cloud: GaussianCloud = deserialize_from(decompressed).expect("failed to decode cloud"); | ||
|
||
cloud | ||
} | ||
} |
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,30 @@ | ||
use flexbuffers::{ | ||
FlexbufferSerializer, | ||
Reader, | ||
}; | ||
use serde::{ | ||
Deserialize, | ||
Serialize, | ||
}; | ||
|
||
use crate::{ | ||
GaussianCloud, | ||
io::codec::GaussianCloudCodec, | ||
}; | ||
|
||
|
||
impl GaussianCloudCodec for GaussianCloud { | ||
fn encode(&self) -> Vec<u8> { | ||
let mut serializer = FlexbufferSerializer::new(); | ||
self.serialize(&mut serializer).expect("failed to serialize cloud"); | ||
|
||
serializer.view().to_vec() | ||
} | ||
|
||
fn decode(data: &[u8]) -> Self { | ||
let reader = Reader::get_root(data).expect("failed to read flexbuffer"); | ||
let cloud = GaussianCloud::deserialize(reader).expect("deserialization failed"); | ||
|
||
cloud | ||
} | ||
} |
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,5 @@ | ||
#[cfg(feature = "io_bincode2")] | ||
pub mod bincode2; | ||
|
||
#[cfg(feature = "io_flexbuffers")] | ||
pub mod flexbuffers; |
Oops, something went wrong.