Skip to content

Commit

Permalink
Replace usages of lazy_static with LazyLock (#1214)
Browse files Browse the repository at this point in the history
fix #1139
  • Loading branch information
robert3005 authored Nov 5, 2024
1 parent 6bcc279 commit 6904ea0
Show file tree
Hide file tree
Showing 18 changed files with 334 additions and 197 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ humansize = "2.1.3"
indicatif = "0.17.8"
itertools = "0.13.0"
jiff = "0.1.8"
lazy_static = "1.4.0"
leb128 = "0.2.5"
libfuzzer-sys = "0.4"
log = "0.4.21"
mimalloc = "0.1.42"
Expand Down Expand Up @@ -156,7 +154,7 @@ vortex-runend-bool = { version = "0.14.0", path = "./encodings/runend-bool" }
vortex-scalar = { version = "0.14.0", path = "./vortex-scalar", default-features = false }
vortex-schema = { version = "0.14.0", path = "./vortex-schema" }
vortex-serde = { version = "0.14.0", path = "./vortex-serde", default-features = false }
vortex-all = { version = "0.14.0", path = "./vortex-all" }
vortex-all = { version = "0.14.0", path = "./vortex-all" }
vortex-sampling-compressor = { version = "0.14.0", path = "./vortex-sampling-compressor" }
vortex-zigzag = { version = "0.14.0", path = "./encodings/zigzag" }
# END crates published by this project
Expand Down
1 change: 0 additions & 1 deletion bench-vortex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ homedir = { workspace = true }
humansize = { workspace = true }
indicatif = { workspace = true }
itertools = { workspace = true }
lazy_static = { workspace = true }
log = { workspace = true }
mimalloc = { workspace = true }
object_store = { workspace = true, features = ["aws"] }
Expand Down
23 changes: 11 additions & 12 deletions bench-vortex/benches/datafusion.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::sync::{Arc, LazyLock};

use arrow_array::builder::{StringBuilder, UInt32Builder};
use arrow_array::RecordBatch;
Expand All @@ -11,7 +11,6 @@ use datafusion::execution::memory_pool::human_readable_size;
use datafusion::functions_aggregate::count::count_distinct;
use datafusion::logical_expr::lit;
use datafusion::prelude::{col, DataFrame, SessionContext};
use lazy_static::lazy_static;
use vortex::aliases::hash_set::HashSet;
use vortex::compress::CompressionStrategy;
use vortex::dict::DictEncoding;
Expand All @@ -26,24 +25,24 @@ use vortex::sampling_compressor::SamplingCompressor;
use vortex::{Array, Context};
use vortex_datafusion::memory::{VortexMemTable, VortexMemTableOptions};

lazy_static! {
pub static ref CTX: Context = Context::default().with_encodings([
pub static CTX: LazyLock<Context> = LazyLock::new(|| {
Context::default().with_encodings([
&BitPackedEncoding as EncodingRef,
&DictEncoding,
&FoREncoding,
&DeltaEncoding
]);
}
&DeltaEncoding,
])
});

lazy_static! {
pub static ref COMPRESSORS: HashSet<CompressorRef<'static>> = [
pub static COMPRESSORS: LazyLock<HashSet<CompressorRef<'static>>> = LazyLock::new(|| {
[
&BITPACK_WITH_PATCHES as CompressorRef<'static>,
&DictCompressor,
&FoRCompressor,
&DeltaCompressor
&DeltaCompressor,
]
.into();
}
.into()
});

fn toy_dataset_arrow() -> RecordBatch {
// 64,000 rows of string and numeric data.
Expand Down
13 changes: 7 additions & 6 deletions bench-vortex/benches/tokio_runtime.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use lazy_static::lazy_static;
use tokio::runtime::Runtime;
use std::sync::LazyLock;

use tokio::runtime::{Builder, Runtime};
use vortex::error::{VortexError, VortexExpect};

lazy_static! {
pub static ref TOKIO_RUNTIME: Runtime = tokio::runtime::Builder::new_current_thread()
pub static TOKIO_RUNTIME: LazyLock<Runtime> = LazyLock::new(|| {
Builder::new_current_thread()
.enable_all()
.build()
.map_err(VortexError::IOError)
.vortex_expect("tokio runtime must not fail to start");
}
.vortex_expect("tokio runtime must not fail to start")
});
22 changes: 12 additions & 10 deletions bench-vortex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use std::env::temp_dir;
use std::fs::{create_dir_all, File};
use std::future::Future;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::sync::{Arc, LazyLock};

use arrow_array::RecordBatchReader;
use itertools::Itertools;
use lazy_static::lazy_static;
use log::LevelFilter;
use parquet::arrow::arrow_reader::ParquetRecordBatchReaderBuilder;
use simplelog::{ColorChoice, Config, TermLogger, TerminalMode};
Expand Down Expand Up @@ -44,13 +43,16 @@ pub mod taxi_data;
pub mod tpch;
pub mod vortex_utils;

lazy_static! {
pub static ref CTX: Arc<Context> = Arc::new(
pub static CTX: LazyLock<Arc<Context>> = LazyLock::new(|| {
Arc::new(
Context::default()
.with_encodings(SamplingCompressor::default().used_encodings())
.with_encoding(&DeltaEncoding)
);
pub static ref COMPRESSORS: HashSet<CompressorRef<'static>> = [
.with_encoding(&DeltaEncoding),
)
});

pub static COMPRESSORS: LazyLock<HashSet<CompressorRef<'static>>> = LazyLock::new(|| {
[
&ALPCompressor as CompressorRef<'static>,
&ALPRDCompressor,
&DictCompressor,
Expand All @@ -60,10 +62,10 @@ lazy_static! {
&DateTimePartsCompressor,
&DEFAULT_RUN_END_COMPRESSOR,
&RoaringBoolCompressor,
&SparseCompressor
&SparseCompressor,
]
.into();
}
.into()
});

/// Creates a file if it doesn't already exist.
/// NB: Does NOT modify the given path to ensure that it resides in the data directory.
Expand Down
Loading

0 comments on commit 6904ea0

Please sign in to comment.