• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vortex-data / vortex / 16723929511

04 Aug 2025 01:02PM UTC coverage: 83.425%. First build
16723929511

Pull #4104

github

web-flow
Merge 1f6bd3ebf into 1b41ff613
Pull Request #4104: perf[duckdb]: add file footer caching

89 of 98 new or added lines in 7 files covered. (90.82%)

46426 of 55650 relevant lines covered (83.42%)

450802.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.75
/vortex-duckdb/src/duckdb/object_cache.rs
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright the Vortex contributors
3

4
use std::ffi::CString;
5
use std::os::raw::c_void;
6

7
use vortex::error::{VortexUnwrap, vortex_err};
8

9
use crate::{cpp, wrapper};
10

11
/// Custom deleter function for Box<T> allocated in Rust
12
unsafe extern "C-unwind" fn rust_box_deleter<T>(ptr: *mut c_void) {
203✔
13
    if !ptr.is_null() {
203✔
14
        unsafe {
203✔
15
            let _ = Box::from_raw(ptr as *mut T);
203✔
16
        }
203✔
NEW
17
    }
×
18
}
203✔
19

NEW
20
wrapper!(ObjectCache, cpp::duckdb_vx_object_cache, |_| {});
×
21

22
impl ObjectCache {
23
    /// Store an entry in the object cache with the given key.
24
    /// The entry will be converted to an opaque pointer and stored.
25
    /// Uses a proper deleter to ensure memory is freed when the cache entry is removed.
26
    pub fn put<T: 'static>(&self, key: &str, entry: T) -> *mut T {
203✔
27
        let key_cstr = CString::new(key)
203✔
28
            .map_err(|e| vortex_err!("invalid key: {}", e))
203✔
29
            .vortex_unwrap();
203✔
30
        let opaque_ptr = Box::into_raw(Box::new(entry));
203✔
31

32
        unsafe {
203✔
33
            cpp::duckdb_vx_object_cache_put(
203✔
34
                self.as_ptr(),
203✔
35
                key_cstr.as_ptr(),
203✔
36
                opaque_ptr as *mut c_void,
203✔
37
                Some(rust_box_deleter::<T>),
203✔
38
            );
203✔
39
        }
203✔
40
        opaque_ptr
203✔
41
    }
203✔
42

43
    /// Retrieve an entry from the object cache with the given key.
44
    /// Returns None if the key is not found.
45
    pub fn get<T>(&self, key: &str) -> Option<&T> {
204✔
46
        let key_cstr = CString::new(key)
204✔
47
            .map_err(|e| vortex_err!("invalid key: {}", e))
204✔
48
            .vortex_unwrap();
204✔
49

50
        unsafe {
51
            let opaque_ptr = cpp::duckdb_vx_object_cache_get(self.as_ptr(), key_cstr.as_ptr());
204✔
52
            (!opaque_ptr.is_null())
204✔
53
                .then_some((opaque_ptr as *const T).as_ref())
204✔
54
                .flatten()
204✔
55
        }
56
    }
204✔
57
}
58

59
// This is Send + Sync since the cache has a mutex wrapper.
60
unsafe impl Send for ObjectCache {}
61
unsafe impl Sync for ObjectCache {}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc