-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a simpler cache dedicated to just decode JPEGs (#1550)
* New cache for decoded tensors * Use the tensor_decode_cache * Actually track/purge the decode cache * At least log warning if the image can't be decoded * Pull in the zero-copy deserialization for ArrowBinary * Bump up decode cache to 4G on non-wasm targets
- Loading branch information
Showing
14 changed files
with
362 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
107 changes: 107 additions & 0 deletions
107
crates/re_log_types/src/component_types/arrow_convert_shims.rs
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,107 @@ | ||
//! Assorted shims that should make their way back to [arrow2-convert](https://github.com/DataEngineeringLabs/arrow2-convert/) | ||
use std::ops::Index; | ||
|
||
use arrow2::{ | ||
array::{Array, BinaryArray}, | ||
buffer::Buffer, | ||
}; | ||
use arrow2_convert::{ | ||
deserialize::{ArrowArray, ArrowDeserialize}, | ||
ArrowField, ArrowSerialize, | ||
}; | ||
|
||
/// Shim to enable zero-copy arrow deserialization for `Buffer<u8>` | ||
/// Can be removed when: [arrow2-convert#103](https://github.com/DataEngineeringLabs/arrow2-convert/pull/103) lands | ||
#[derive(Clone, Debug, PartialEq, ArrowField, ArrowSerialize)] | ||
#[arrow_field(transparent)] | ||
pub struct BinaryBuffer(pub Buffer<u8>); | ||
|
||
impl BinaryBuffer { | ||
pub fn as_slice(&self) -> &[u8] { | ||
self.0.as_slice() | ||
} | ||
} | ||
|
||
impl Index<usize> for BinaryBuffer { | ||
type Output = u8; | ||
fn index(&self, i: usize) -> &u8 { | ||
&self.0[i] | ||
} | ||
} | ||
|
||
impl From<Vec<u8>> for BinaryBuffer { | ||
fn from(v: Vec<u8>) -> Self { | ||
Self(v.into()) | ||
} | ||
} | ||
|
||
/// Iterator for for [`BufferBinaryArray`] | ||
pub struct BufferBinaryArrayIter<'a> { | ||
index: usize, | ||
array: &'a BinaryArray<i32>, | ||
} | ||
|
||
impl<'a> Iterator for BufferBinaryArrayIter<'a> { | ||
type Item = Option<Buffer<u8>>; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
if self.index >= self.array.len() { | ||
None | ||
} else { | ||
if let Some(validity) = self.array.validity() { | ||
if !validity.get_bit(self.index) { | ||
self.index += 1; | ||
return Some(None); | ||
} | ||
} | ||
let (start, end) = self.array.offsets().start_end(self.index); | ||
self.index += 1; | ||
Some(Some(self.array.values().clone().slice(start, end - start))) | ||
} | ||
} | ||
} | ||
|
||
/// Internal `ArrowArray` helper to iterate over a `BinaryArray` while exposing Buffer slices | ||
pub struct BufferBinaryArray; | ||
|
||
extern "C" { | ||
fn do_not_call_into_iter(); // we never define this function, so the linker will fail | ||
} | ||
|
||
impl<'a> IntoIterator for &'a BufferBinaryArray { | ||
type Item = Option<Buffer<u8>>; | ||
|
||
type IntoIter = BufferBinaryArrayIter<'a>; | ||
|
||
fn into_iter(self) -> Self::IntoIter { | ||
#[allow(unsafe_code)] | ||
// SAFETY: | ||
// This exists so we get a link-error if some code tries to call into_iter | ||
// Iteration should only happen via iter_from_array_ref. | ||
// This is a quirk of the way the traits work in arrow2_convert. | ||
unsafe { | ||
do_not_call_into_iter(); | ||
} | ||
unreachable!() | ||
} | ||
} | ||
|
||
impl ArrowArray for BufferBinaryArray { | ||
type BaseArrayType = BinaryArray<i32>; | ||
#[inline] | ||
fn iter_from_array_ref(a: &dyn Array) -> <&Self as IntoIterator>::IntoIter { | ||
let b = a.as_any().downcast_ref::<Self::BaseArrayType>().unwrap(); | ||
|
||
BufferBinaryArrayIter { index: 0, array: b } | ||
} | ||
} | ||
|
||
impl ArrowDeserialize for BinaryBuffer { | ||
type ArrayType = BufferBinaryArray; | ||
|
||
#[inline] | ||
fn arrow_deserialize(v: Option<Buffer<u8>>) -> Option<Self> { | ||
v.map(BinaryBuffer) | ||
} | ||
} |
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
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
Oops, something went wrong.
79af754
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust Benchmark
datastore/insert/batch/rects/insert
558707
ns/iter (± 3674
)552534
ns/iter (± 1423
)1.01
datastore/latest_at/batch/rects/query
1851
ns/iter (± 8
)1829
ns/iter (± 13
)1.01
datastore/latest_at/missing_components/primary
286
ns/iter (± 8
)285
ns/iter (± 0
)1.00
datastore/latest_at/missing_components/secondaries
430
ns/iter (± 3
)431
ns/iter (± 1
)1.00
datastore/range/batch/rects/query
148720
ns/iter (± 1220
)153436
ns/iter (± 214
)0.97
mono_points_arrow/generate_message_bundles
44586702
ns/iter (± 910411
)49693844
ns/iter (± 1067596
)0.90
mono_points_arrow/generate_messages
124787569
ns/iter (± 1160849
)135740691
ns/iter (± 1216667
)0.92
mono_points_arrow/encode_log_msg
151979051
ns/iter (± 626032
)164144726
ns/iter (± 935636
)0.93
mono_points_arrow/encode_total
325667766
ns/iter (± 1242883
)353332279
ns/iter (± 1567920
)0.92
mono_points_arrow/decode_log_msg
176756481
ns/iter (± 1009934
)187175579
ns/iter (± 877284
)0.94
mono_points_arrow/decode_message_bundles
63727124
ns/iter (± 819875
)72762833
ns/iter (± 1060684
)0.88
mono_points_arrow/decode_total
238442946
ns/iter (± 1572409
)256330976
ns/iter (± 1971975
)0.93
batch_points_arrow/generate_message_bundles
330467
ns/iter (± 3296
)331425
ns/iter (± 1759
)1.00
batch_points_arrow/generate_messages
6349
ns/iter (± 52
)6271
ns/iter (± 109
)1.01
batch_points_arrow/encode_log_msg
367540
ns/iter (± 1702
)365537
ns/iter (± 1261
)1.01
batch_points_arrow/encode_total
718192
ns/iter (± 4568
)714046
ns/iter (± 2532
)1.01
batch_points_arrow/decode_log_msg
351033
ns/iter (± 1404
)349382
ns/iter (± 1704
)1.00
batch_points_arrow/decode_message_bundles
2069
ns/iter (± 15
)2111
ns/iter (± 5
)0.98
batch_points_arrow/decode_total
353948
ns/iter (± 1224
)355057
ns/iter (± 1096
)1.00
arrow_mono_points/insert
6017500893
ns/iter (± 13506697
)6840618970
ns/iter (± 24686392
)0.88
arrow_mono_points/query
1734489
ns/iter (± 18384
)1758997
ns/iter (± 9322
)0.99
arrow_batch_points/insert
2649847
ns/iter (± 13868
)2605055
ns/iter (± 11034
)1.02
arrow_batch_points/query
16883
ns/iter (± 120
)16927
ns/iter (± 71
)1.00
arrow_batch_vecs/insert
42111
ns/iter (± 320
)42747
ns/iter (± 106
)0.99
arrow_batch_vecs/query
504835
ns/iter (± 3792
)506043
ns/iter (± 398
)1.00
tuid/Tuid::random
34
ns/iter (± 0
)34
ns/iter (± 0
)1
This comment was automatically generated by workflow using github-action-benchmark.