Skip to content

Commit 7de2da2

Browse files
committed
Add zstd output compression and configurable output level. Contribution from malfoy <antoine.limasset@gmail.com> pr #71
1 parent 94e7306 commit 7de2da2

13 files changed

Lines changed: 96 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/assembler_pipeline/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use std::{
44
any::Any,
55
path::{Path, PathBuf},
66
sync::Arc,
7+
sync::atomic::Ordering,
78
};
89

910
use ::dynamic_dispatch::dynamic_dispatch;
1011
use colors::colors_manager::{ColorsManager, color_types::PartialUnitigsColorStructure};
11-
use config::{SwapPriority, get_compression_level_info, get_memory_mode};
12+
use config::{OUTPUT_COMPRESSION_LEVEL, SwapPriority, get_compression_level_info, get_memory_mode};
1213
use hashes::HashFunctionFactory;
1314
use io::{
1415
concurrent::temp_reads::extra_data::{
@@ -71,10 +72,15 @@ pub fn get_final_output_writer<
7172
>(
7273
output_file: &Path,
7374
) -> W {
75+
let output_compression_level = OUTPUT_COMPRESSION_LEVEL.load(Ordering::Relaxed);
76+
7477
match output_file.extension() {
7578
Some(ext) => match ext.to_string_lossy().to_string().as_str() {
76-
"lz4" => W::new_compressed_lz4(&output_file, 2),
77-
"gz" => W::new_compressed_gzip(&output_file, 2),
79+
"lz4" => W::new_compressed_lz4(&output_file, output_compression_level.min(16)),
80+
"gz" => W::new_compressed_gzip(&output_file, output_compression_level.min(9)),
81+
"zst" | "zstd" => {
82+
W::new_compressed_zstd(&output_file, output_compression_level.min(22))
83+
}
7884
_ => W::new_plain(&output_file),
7985
},
8086
None => W::new_plain(&output_file),

crates/cmdline/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ byteorder = "1.5.0"
1515
itertools = "0.13.0"
1616
lazy_static = "1.5.0"
1717
lz4 = "1.25.0"
18+
zstd = "0.13.2"
1819
rayon = "1.10.0"
1920
serde = "1.0.203"
2021
hashbrown = "0.15.3"

crates/cmdline/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use colors::DefaultColorsSerializer;
1111
use colors::colors_manager::ColorMapReader;
1212
use colors::storage::deserializer::ColorsDeserializer;
1313
use config::ColorIndexType;
14+
use config::OUTPUT_COMPRESSION_LEVEL;
1415
use ggcat_api::{ExtraElaboration, GGCATConfig, GGCATInstance, GfaVersion};
1516
use ggcat_logging::UnrecoverableErrorLogging;
1617
use io::sequences_stream::general::GeneralSequenceBlockData;
@@ -136,6 +137,10 @@ struct CommonArgs {
136137
)]
137138
pub intermediate_compression_level: Option<u32>,
138139

140+
/// Compression level for final output files (applies to .lz4/.gz/.zst/.zstd outputs)
141+
#[arg(long = "output-compression-level", default_value = "2")]
142+
pub output_compression_level: u32,
143+
139144
#[arg(hide = true, long = "only-bstats")]
140145
pub only_bstats: bool,
141146
}
@@ -313,6 +318,7 @@ fn initialize(args: &CommonArgs, out_file: &PathBuf) -> &'static GGCATInstance {
313318
ggcat_api::debug::DEBUG_KEEP_FILES.store(args.keep_temp_files, Ordering::Relaxed);
314319
*ggcat_api::debug::BUCKETS_COUNT_LOG_FORCE.lock() = args.buckets_count_log;
315320
ggcat_api::debug::DEBUG_ONLY_BSTATS.store(args.only_bstats, Ordering::Relaxed);
321+
OUTPUT_COMPRESSION_LEVEL.store(args.output_compression_level, Ordering::Relaxed);
316322
*ggcat_api::debug::DEBUG_HASH_TYPE.lock() = match args.hash_type {
317323
HashType::Auto => ggcat_api::HashType::Auto,
318324
HashType::SeqHash => ggcat_api::HashType::SeqHash,

crates/config/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ impl SwapPriority {
149149
pub static KEEP_FILES: AtomicBool = AtomicBool::new(false);
150150
pub static INTERMEDIATE_COMPRESSION_LEVEL_SLOW: AtomicU32 = AtomicU32::new(3);
151151
pub static INTERMEDIATE_COMPRESSION_LEVEL_FAST: AtomicU32 = AtomicU32::new(0);
152+
pub static OUTPUT_COMPRESSION_LEVEL: AtomicU32 = AtomicU32::new(2);
152153
pub static PREFER_MEMORY: AtomicBool = AtomicBool::new(false);
153154

154155
pub fn get_memory_mode(swap_priority: usize) -> MemoryFileMode {

crates/querier/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ csv = "1.3.0"
3333
parking_lot = "0.12.3"
3434
lz4 = "1.25.0"
3535
flate2 = "1.0.30"
36+
zstd = "0.13.2"
3637
ggcat-logging = { version = "2.1.0", path = "../logging" }
3738
anyhow = "1.0.89"
3839
typenum = "1.18.0"

crates/querier/src/pipeline/colored_query_output.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::structs::query_colored_counters::{ColorsRange, QueryColoredCountersSe
33
use colors::colors_manager::ColorMapReader;
44
use colors::colors_manager::{ColorsManager, ColorsMergeManager};
55
use config::{
6-
ColorIndexType, KEEP_FILES, QUERIES_COUNT_MIN_BATCH, SwapPriority, get_compression_level_info,
7-
get_memory_mode,
6+
ColorIndexType, KEEP_FILES, OUTPUT_COMPRESSION_LEVEL, QUERIES_COUNT_MIN_BATCH, SwapPriority,
7+
get_compression_level_info, get_memory_mode,
88
};
99
use flate2::Compression;
1010
use ggcat_logging::UnrecoverableErrorLogging;
@@ -32,6 +32,7 @@ enum QueryOutputFileWriter {
3232
Plain(File),
3333
LZ4Compressed(lz4::Encoder<File>),
3434
GzipCompressed(flate2::write::GzEncoder<File>),
35+
ZstdCompressed(zstd::stream::write::Encoder<'static, File>),
3536
}
3637

3738
impl Write for QueryOutputFileWriter {
@@ -40,6 +41,7 @@ impl Write for QueryOutputFileWriter {
4041
QueryOutputFileWriter::Plain(w) => w.write(buf),
4142
QueryOutputFileWriter::LZ4Compressed(w) => w.write(buf),
4243
QueryOutputFileWriter::GzipCompressed(w) => w.write(buf),
44+
QueryOutputFileWriter::ZstdCompressed(w) => w.write(buf),
4345
}
4446
}
4547

@@ -48,6 +50,7 @@ impl Write for QueryOutputFileWriter {
4850
QueryOutputFileWriter::Plain(w) => w.flush(),
4951
QueryOutputFileWriter::LZ4Compressed(w) => w.flush(),
5052
QueryOutputFileWriter::GzipCompressed(w) => w.flush(),
53+
QueryOutputFileWriter::ZstdCompressed(w) => w.flush(),
5154
}
5255
}
5356
}
@@ -85,17 +88,29 @@ pub fn colored_query_output<MH: HashFunctionFactory, CX: ColorsManager>(
8588
let query_output_file = File::create(&output_file)
8689
.log_unrecoverable_error_with_data("Cannot create output file", output_file.display())?;
8790

91+
let output_compression_level = OUTPUT_COMPRESSION_LEVEL.load(Ordering::Relaxed);
92+
8893
let query_output = Mutex::new((
8994
BufWriter::new(
9095
match output_file.extension().map(|e| e.to_str()).flatten() {
9196
Some("lz4") => QueryOutputFileWriter::LZ4Compressed(
9297
lz4::EncoderBuilder::new()
93-
.level(4)
98+
.level(output_compression_level.min(16))
9499
.build(query_output_file)
95100
.unwrap(),
96101
),
97-
Some("gz") => QueryOutputFileWriter::GzipCompressed(
98-
flate2::GzBuilder::new().write(query_output_file, Compression::default()),
102+
Some("gz") => {
103+
QueryOutputFileWriter::GzipCompressed(flate2::GzBuilder::new().write(
104+
query_output_file,
105+
Compression::new(output_compression_level.min(9)),
106+
))
107+
}
108+
Some("zst") | Some("zstd") => QueryOutputFileWriter::ZstdCompressed(
109+
zstd::stream::write::Encoder::new(
110+
query_output_file,
111+
output_compression_level.min(22) as i32,
112+
)
113+
.unwrap(),
99114
),
100115
_ => QueryOutputFileWriter::Plain(query_output_file),
101116
},

crates/sequence_output/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ byteorder = "1.5.0"
2828
flate2 = "1.1.9"
2929
parking_lot = "0.12.5"
3030
serde = "1.0.228"
31+
zstd = "0.13.3"
3132

3233

3334
[features]

crates/sequence_output/src/structured_sequences.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ pub trait StructuredSequenceBackendInit: Sync + Send + Sized {
4141
unimplemented!()
4242
}
4343

44+
fn new_compressed_zstd(_path: impl AsRef<Path>, _level: u32) -> Self {
45+
unimplemented!()
46+
}
47+
4448
fn new_plain(_path: impl AsRef<Path>) -> Self {
4549
unimplemented!()
4650
}

crates/sequence_output/src/structured_sequences/binary.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ impl<CX: ColorsManager, LinksInfo: IdentSequenceWriter + SequenceExtraData>
8989
unimplemented!()
9090
}
9191

92+
fn new_compressed_zstd(_path: impl AsRef<Path>, _level: u32) -> Self {
93+
unimplemented!()
94+
}
95+
9296
fn new_plain(_path: impl AsRef<Path>) -> Self {
9397
unimplemented!()
9498
}

0 commit comments

Comments
 (0)