Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace serde_json with simd_json #3174

Draft
wants to merge 2 commits into
base: latest
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 117 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion src/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ rayon = { version = "1.10.0", optional = true }
rkyv = { version = "0.7.44", optional = true }
roaring = "0.10.9"
roots = "0.0.8"
simd-json = "0.14.3"
serde = { version = "1.0.216", features = ["derive"] }
serde_json = "1.0.133"
statrs = "0.18.0"
streaming-stats = "0.2.3"
thiserror = "2.0"
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub enum SourmashError {
StorageError(#[from] crate::storage::StorageError),

#[error(transparent)]
SerdeError(#[from] serde_json::error::Error),
SerdeError(#[from] simd_json::Error),

#[error(transparent)]
NifflerError(#[from] niffler::Error),
Expand Down
6 changes: 3 additions & 3 deletions src/core/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@
{
let (rdr, _format) = niffler::get_reader(Box::new(rdr))?;

let sigs: Vec<Signature> = serde_json::from_reader(rdr)?;
let sigs: Vec<Signature> = simd_json::from_reader(rdr)?;
Ok(sigs)
}

Expand Down Expand Up @@ -787,7 +787,7 @@
where
W: io::Write,
{
serde_json::to_writer(writer, &vec![&self])?;
simd_json::to_writer(writer, &vec![&self])?;
Ok(())
}
}
Expand All @@ -797,7 +797,7 @@
where
W: io::Write,
{
serde_json::to_writer(writer, &self)?;
simd_json::to_writer(writer, &self)?;

Check warning on line 800 in src/core/src/signature.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/signature.rs#L800

Added line #L800 was not covered by tests
Ok(())
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/src/sketch/minhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl ToWriter for KmerMinHash {
where
W: io::Write,
{
serde_json::to_writer(writer, &self)?;
simd_json::to_writer(writer, &self)?;
Ok(())
}
}
Expand Down Expand Up @@ -875,7 +875,7 @@ impl KmerMinHash {
{
let (rdr, _format) = niffler::get_reader(Box::new(rdr))?;

let mh: KmerMinHash = serde_json::from_reader(rdr)?;
let mh: KmerMinHash = simd_json::from_reader(rdr)?;
Ok(mh)
}
}
Expand Down Expand Up @@ -1140,7 +1140,7 @@ impl ToWriter for KmerMinHashBTree {
where
W: io::Write,
{
serde_json::to_writer(writer, &self)?;
simd_json::to_writer(writer, &self)?;
Ok(())
}
}
Expand Down Expand Up @@ -1633,7 +1633,7 @@ impl KmerMinHashBTree {
{
let (rdr, _format) = niffler::get_reader(Box::new(rdr))?;

let mh: KmerMinHashBTree = serde_json::from_reader(rdr)?;
let mh: KmerMinHashBTree = simd_json::from_reader(rdr)?;
Ok(mh)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub enum JsErrors {
SourmashError(#[from] crate::Error),

#[error(transparent)]
SerdeError(#[from] serde_json::error::Error),
SerdeError(#[from] simd_json::Error),

#[error(transparent)]
NifflerError(#[from] niffler::Error),
Expand Down
4 changes: 2 additions & 2 deletions src/core/tests/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ fn zipstorage_load_file() -> Result<(), Box<dyn std::error::Error>> {

let zs = ZipStorage::from_file(filename.to_str().unwrap())?;

let data = zs.load("v6.sbt.json")?;
let mut data = zs.load("v6.sbt.json")?;

let description: serde_json::Value = serde_json::from_slice(&data[..])?;
let description: simd_json::borrowed::Value = simd_json::from_slice(&mut data[..])?;
assert_eq!(description["version"], 6);

Ok(())
Expand Down
Loading