forked from BigfootDev/flatbuffers
Store vtables sorted in Rust builder (#6765)
* benchmark many vtables * Rust: Store written_table rev-positions sorted. The previous implementation was slow if there were too many tables. Asymototically when inserting the n^th vtable: The old implementation took O(n) lookup steps and O(1) insertion. The new implementation is O(log n) lookup and O(n) insertion. This might be improved further by using a balanced btree. Benchmarking, create_many_tables is 7.5x faster (on my laptop): // Simple vector cache test create_many_tables ... bench: 728,875 ns/iter (+/- 12,279) = 44 MB/s // Sorted vector cache test create_many_tables ... bench: 97,843 ns/iter (+/- 4,430) = 334 MB/s * Fix lints Co-authored-by: Casper Neo <cneo@google.com>
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
use std::ptr::write_bytes;
|
||||
|
||||
use crate::endian_scalar::{emplace_scalar, read_scalar_at};
|
||||
use crate::endian_scalar::emplace_scalar;
|
||||
use crate::primitives::*;
|
||||
|
||||
/// VTableWriter compartmentalizes actions needed to create a vtable.
|
||||
@@ -54,16 +54,6 @@ impl<'a> VTableWriter<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets an object field offset from the vtable. Only used for debugging.
|
||||
///
|
||||
/// Note that this expects field offsets (which are like pointers), not
|
||||
/// field ids (which are like array indices).
|
||||
#[inline(always)]
|
||||
pub fn get_field_offset(&self, vtable_offset: VOffsetT) -> VOffsetT {
|
||||
let idx = vtable_offset as usize;
|
||||
unsafe { read_scalar_at::<VOffsetT>(&self.buf, idx) }
|
||||
}
|
||||
|
||||
/// Writes an object field offset into the vtable.
|
||||
///
|
||||
/// Note that this expects field offsets (which are like pointers), not
|
||||
|
||||
Reference in New Issue
Block a user