Skip to content

Commit 2f6cb6d

Browse files
authored
Remove layout strategy generics (#4576)
Makes compile times really really slow. I kept generic constructors for the nice API --------- Signed-off-by: Nicholas Gates <nick@nickgates.com>
1 parent 29e5bb9 commit 2f6cb6d

7 files changed

Lines changed: 66 additions & 94 deletions

File tree

vortex-layout/src/layouts/buffered.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use std::collections::VecDeque;
5+
use std::sync::Arc;
56

67
use async_stream::try_stream;
78
use async_trait::async_trait;
@@ -16,22 +17,22 @@ use crate::{
1617
};
1718

1819
#[derive(Clone)]
19-
pub struct BufferedStrategy<S> {
20-
child: S,
20+
pub struct BufferedStrategy {
21+
child: Arc<dyn LayoutStrategy>,
2122
buffer_size: u64,
2223
}
2324

24-
impl<S: LayoutStrategy> BufferedStrategy<S> {
25-
pub fn new(child: S, buffer_size: u64) -> Self {
26-
Self { child, buffer_size }
25+
impl BufferedStrategy {
26+
pub fn new<S: LayoutStrategy>(child: S, buffer_size: u64) -> Self {
27+
Self {
28+
child: Arc::new(child),
29+
buffer_size,
30+
}
2731
}
2832
}
2933

3034
#[async_trait]
31-
impl<S> LayoutStrategy for BufferedStrategy<S>
32-
where
33-
S: LayoutStrategy,
34-
{
35+
impl LayoutStrategy for BufferedStrategy {
3536
async fn write_stream(
3637
&self,
3738
ctx: &ArrayContext,

vortex-layout/src/layouts/chunked/writer.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// SPDX-License-Identifier: Apache-2.0
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

4+
use std::sync::Arc;
5+
46
use async_trait::async_trait;
57
use futures::StreamExt;
68
use futures::stream::once;
@@ -16,25 +18,21 @@ use crate::{
1618
};
1719

1820
#[derive(Clone)]
19-
pub struct ChunkedLayoutStrategy<S> {
21+
pub struct ChunkedLayoutStrategy {
2022
/// The layout strategy for each chunk.
21-
pub chunk_strategy: S,
23+
pub chunk_strategy: Arc<dyn LayoutStrategy>,
2224
}
2325

24-
impl<S> ChunkedLayoutStrategy<S>
25-
where
26-
S: LayoutStrategy,
27-
{
28-
pub fn new(chunk_strategy: S) -> Self {
29-
Self { chunk_strategy }
26+
impl ChunkedLayoutStrategy {
27+
pub fn new<S: LayoutStrategy>(chunk_strategy: S) -> Self {
28+
Self {
29+
chunk_strategy: Arc::new(chunk_strategy),
30+
}
3031
}
3132
}
3233

3334
#[async_trait]
34-
impl<S> LayoutStrategy for ChunkedLayoutStrategy<S>
35-
where
36-
S: LayoutStrategy,
37-
{
35+
impl LayoutStrategy for ChunkedLayoutStrategy {
3836
async fn write_stream(
3937
&self,
4038
ctx: &ArrayContext,

vortex-layout/src/layouts/compressed.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,28 @@ impl CompressorPlugin for crate::layouts::compact::CompactCompressor {
5656

5757
/// A layout writer that compresses chunks.
5858
#[derive(Clone)]
59-
pub struct CompressingStrategy<S> {
60-
child: S,
59+
pub struct CompressingStrategy {
60+
child: Arc<dyn LayoutStrategy>,
6161
compressor: Arc<dyn CompressorPlugin>,
6262
executor: Arc<dyn TaskExecutor>,
6363
parallelism: usize,
6464
}
6565

66-
impl<S: LayoutStrategy> CompressingStrategy<S> {
66+
impl CompressingStrategy {
6767
/// Create a new writer that uses the BtrBlocks-style cascading compressor to compress chunks.
6868
///
6969
/// This provides a good balance between decoding speed and small file size.
7070
///
7171
/// Set `exclude_int_dict_encoding` to true to prevent dictionary encoding of integer arrays,
7272
/// which is useful when compressing dictionary codes to avoid recursive dictionary encoding.
73-
pub fn new_btrblocks(
73+
pub fn new_btrblocks<S: LayoutStrategy>(
7474
child: S,
7575
executor: Arc<dyn TaskExecutor>,
7676
parallelism: usize,
7777
exclude_int_dict_encoding: bool,
7878
) -> Self {
7979
Self {
80-
child,
80+
child: Arc::new(child),
8181
compressor: Arc::new(BtrBlocksCompressor {
8282
exclude_int_dict_encoding,
8383
}),
@@ -94,29 +94,29 @@ impl<S: LayoutStrategy> CompressingStrategy<S> {
9494
///
9595
/// [`CompactCompressor`]: crate::layouts::compact::CompactCompressor
9696
#[cfg(feature = "zstd")]
97-
pub fn new_compact(
97+
pub fn new_compact<S: LayoutStrategy>(
9898
child: S,
9999
compressor: crate::layouts::compact::CompactCompressor,
100100
executor: Arc<dyn TaskExecutor>,
101101
parallelism: usize,
102102
) -> Self {
103103
Self {
104-
child,
104+
child: Arc::new(child),
105105
compressor: Arc::new(compressor),
106106
executor,
107107
parallelism,
108108
}
109109
}
110110

111111
/// Create a new compressor from a plugin interface.
112-
pub fn new_opaque<C: CompressorPlugin>(
112+
pub fn new_opaque<S: LayoutStrategy, C: CompressorPlugin>(
113113
child: S,
114114
compressor: C,
115115
executor: Arc<dyn TaskExecutor>,
116116
parallelism: usize,
117117
) -> Self {
118118
Self {
119-
child,
119+
child: Arc::new(child),
120120
compressor: Arc::new(compressor),
121121
executor,
122122
parallelism,
@@ -125,10 +125,7 @@ impl<S: LayoutStrategy> CompressingStrategy<S> {
125125
}
126126

127127
#[async_trait]
128-
impl<S> LayoutStrategy for CompressingStrategy<S>
129-
where
130-
S: LayoutStrategy,
131-
{
128+
impl LayoutStrategy for CompressingStrategy {
132129
async fn write_stream(
133130
&self,
134131
ctx: &ArrayContext,

vortex-layout/src/layouts/dict/writer/mod.rs renamed to vortex-layout/src/layouts/dict/writer.rs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,44 +51,34 @@ impl Default for DictLayoutOptions {
5151
/// encodes chunks into dictionaries. When the dict constraints are hit, a
5252
/// new dictionary is created.
5353
#[derive(Clone)]
54-
pub struct DictStrategy<Codes, Values, Fallback> {
55-
codes: Codes,
56-
values: Values,
57-
fallback: Fallback,
54+
pub struct DictStrategy {
55+
codes: Arc<dyn LayoutStrategy>,
56+
values: Arc<dyn LayoutStrategy>,
57+
fallback: Arc<dyn LayoutStrategy>,
5858
options: DictLayoutOptions,
5959
executor: Arc<dyn TaskExecutor>,
6060
}
6161

62-
impl<Codes, Values, Fallback> DictStrategy<Codes, Values, Fallback>
63-
where
64-
Codes: LayoutStrategy,
65-
Values: LayoutStrategy,
66-
Fallback: LayoutStrategy,
67-
{
68-
pub fn new(
62+
impl DictStrategy {
63+
pub fn new<Codes: LayoutStrategy, Values: LayoutStrategy, Fallback: LayoutStrategy>(
6964
codes: Codes,
7065
values: Values,
7166
fallback: Fallback,
7267
options: DictLayoutOptions,
7368
executor: Arc<dyn TaskExecutor>,
7469
) -> Self {
7570
Self {
76-
codes,
77-
values,
78-
fallback,
71+
codes: Arc::new(codes),
72+
values: Arc::new(values),
73+
fallback: Arc::new(fallback),
7974
options,
8075
executor,
8176
}
8277
}
8378
}
8479

8580
#[async_trait]
86-
impl<Codes, Values, Fallback> LayoutStrategy for DictStrategy<Codes, Values, Fallback>
87-
where
88-
Codes: LayoutStrategy,
89-
Values: LayoutStrategy,
90-
Fallback: LayoutStrategy,
91-
{
81+
impl LayoutStrategy for DictStrategy {
9282
async fn write_stream(
9383
&self,
9484
ctx: &ArrayContext,

vortex-layout/src/layouts/repartition.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-FileCopyrightText: Copyright the Vortex contributors
33

44
use std::collections::VecDeque;
5+
use std::sync::Arc;
56

67
use async_stream::try_stream;
78
use async_trait::async_trait;
@@ -29,25 +30,22 @@ pub struct RepartitionWriterOptions {
2930
/// Each emitted block (except the last) is at least `block_size_minimum` bytes and contains a
3031
/// multiple of `block_len_multiple` rows.
3132
#[derive(Clone)]
32-
pub struct RepartitionStrategy<S> {
33-
child: S,
33+
pub struct RepartitionStrategy {
34+
child: Arc<dyn LayoutStrategy>,
3435
options: RepartitionWriterOptions,
3536
}
3637

37-
impl<S> RepartitionStrategy<S>
38-
where
39-
S: LayoutStrategy,
40-
{
41-
pub fn new(child: S, options: RepartitionWriterOptions) -> Self {
42-
Self { child, options }
38+
impl RepartitionStrategy {
39+
pub fn new<S: LayoutStrategy>(child: S, options: RepartitionWriterOptions) -> Self {
40+
Self {
41+
child: Arc::new(child),
42+
options,
43+
}
4344
}
4445
}
4546

4647
#[async_trait]
47-
impl<S> LayoutStrategy for RepartitionStrategy<S>
48-
where
49-
S: LayoutStrategy,
50-
{
48+
impl LayoutStrategy for RepartitionStrategy {
5149
async fn write_stream(
5250
&self,
5351
ctx: &ArrayContext,

vortex-layout/src/layouts/struct_/writer.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,21 @@ use crate::{
2525
SequentialStreamExt,
2626
};
2727

28-
pub struct StructStrategy<S> {
29-
child: S,
28+
pub struct StructStrategy {
29+
child: Arc<dyn LayoutStrategy>,
3030
}
3131

3232
/// A [`LayoutStrategy`] that splits a StructArray batch into child layout writers
33-
impl<S> StructStrategy<S>
34-
where
35-
S: LayoutStrategy,
36-
{
37-
pub fn new(child: S) -> Self {
38-
Self { child }
33+
impl StructStrategy {
34+
pub fn new<S: LayoutStrategy>(child: S) -> Self {
35+
Self {
36+
child: Arc::new(child),
37+
}
3938
}
4039
}
4140

4241
#[async_trait]
43-
impl<S> LayoutStrategy for StructStrategy<S>
44-
where
45-
S: LayoutStrategy,
46-
{
42+
impl LayoutStrategy for StructStrategy {
4743
async fn write_stream(
4844
&self,
4945
ctx: &ArrayContext,

vortex-layout/src/layouts/zoned/writer.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,39 +44,31 @@ impl Default for ZonedLayoutOptions {
4444
}
4545
}
4646

47-
pub struct ZonedStrategy<Child, Stats> {
48-
child: Child,
49-
stats: Stats,
47+
pub struct ZonedStrategy {
48+
child: Arc<dyn LayoutStrategy>,
49+
stats: Arc<dyn LayoutStrategy>,
5050
options: ZonedLayoutOptions,
5151
executor: Arc<dyn TaskExecutor>,
5252
}
5353

54-
impl<Child, Stats> ZonedStrategy<Child, Stats>
55-
where
56-
Child: LayoutStrategy,
57-
Stats: LayoutStrategy,
58-
{
59-
pub fn new(
54+
impl ZonedStrategy {
55+
pub fn new<Child: LayoutStrategy, Stats: LayoutStrategy>(
6056
child: Child,
6157
stats: Stats,
6258
options: ZonedLayoutOptions,
6359
executor: Arc<dyn TaskExecutor>,
6460
) -> Self {
6561
Self {
66-
child,
67-
stats,
62+
child: Arc::new(child),
63+
stats: Arc::new(stats),
6864
options,
6965
executor,
7066
}
7167
}
7268
}
7369

7470
#[async_trait]
75-
impl<Child, Stats> LayoutStrategy for ZonedStrategy<Child, Stats>
76-
where
77-
Child: LayoutStrategy,
78-
Stats: LayoutStrategy,
79-
{
71+
impl LayoutStrategy for ZonedStrategy {
8072
async fn write_stream(
8173
&self,
8274
ctx: &ArrayContext,

0 commit comments

Comments
 (0)