@@ -30,8 +30,8 @@ pub trait VortexReadAt: Send + Sync + Clone + 'static {
3030
3131 // TODO(ngates): the read implementation should be able to hint at its latency/throughput
3232 // allowing the caller to make better decisions about how to coalesce reads.
33- fn performance_hint ( & self ) -> usize {
34- 0
33+ fn performance_hint ( & self ) -> PerformanceHint {
34+ PerformanceHint :: default ( )
3535 }
3636
3737 /// Asynchronously get the number of bytes of data readable.
@@ -41,6 +41,34 @@ pub trait VortexReadAt: Send + Sync + Clone + 'static {
4141 fn size ( & self ) -> impl Future < Output = io:: Result < u64 > > + ' static ;
4242}
4343
44+ pub struct PerformanceHint {
45+ coalescing_window : u64 ,
46+ }
47+
48+ impl Default for PerformanceHint {
49+ fn default ( ) -> Self {
50+ Self {
51+ coalescing_window : 2 << 20 , //1MB,
52+ }
53+ }
54+ }
55+
56+ impl PerformanceHint {
57+ pub fn new ( coalescing_window : u64 ) -> Self {
58+ Self { coalescing_window }
59+ }
60+
61+ /// Creates a new instance with a profile appropriate for fast local storage, like memory or files on NVMe devices.
62+ pub fn local ( ) -> Self {
63+ Self :: new ( 0 )
64+ }
65+
66+ /// The maximum distance between two reads that should coalesced into a single operation.
67+ pub fn coalescing_window ( & self ) -> u64 {
68+ self . coalescing_window
69+ }
70+ }
71+
4472impl < T : VortexReadAt > VortexReadAt for Arc < T > {
4573 fn read_byte_range (
4674 & self ,
@@ -50,7 +78,7 @@ impl<T: VortexReadAt> VortexReadAt for Arc<T> {
5078 T :: read_byte_range ( self , pos, len)
5179 }
5280
53- fn performance_hint ( & self ) -> usize {
81+ fn performance_hint ( & self ) -> PerformanceHint {
5482 T :: performance_hint ( self )
5583 }
5684
@@ -79,6 +107,10 @@ impl VortexReadAt for Bytes {
79107 fn size ( & self ) -> impl Future < Output = io:: Result < u64 > > + ' static {
80108 ready ( Ok ( self . len ( ) as u64 ) )
81109 }
110+
111+ fn performance_hint ( & self ) -> PerformanceHint {
112+ PerformanceHint :: local ( )
113+ }
82114}
83115
84116impl VortexReadAt for ByteBuffer {
@@ -98,6 +130,10 @@ impl VortexReadAt for ByteBuffer {
98130 ready ( Ok ( self . slice ( read_start..read_end) . into_inner ( ) ) )
99131 }
100132
133+ fn performance_hint ( & self ) -> PerformanceHint {
134+ PerformanceHint :: local ( )
135+ }
136+
101137 fn size ( & self ) -> impl Future < Output = io:: Result < u64 > > + ' static {
102138 ready ( Ok ( self . len ( ) as u64 ) )
103139 }
0 commit comments