Skip to content

Commit

Permalink
use simd_json instead of serde_json
Browse files Browse the repository at this point in the history
  • Loading branch information
luizirber committed Dec 19, 2024
1 parent a4f39ca commit eb471c8
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 16 deletions.
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 @@ impl Signature {
{
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 @@ impl ToWriter for Signature {
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 @@ impl ToWriter for Vec<&Signature> {
where
W: io::Write,
{
serde_json::to_writer(writer, &self)?;
simd_json::to_writer(writer, &self)?;
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
2 changes: 1 addition & 1 deletion src/core/tests/minhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use proptest::num::u64;
use proptest::proptest;
use sourmash::encodings::HashFunctions;
use sourmash::prelude::ToWriter;
use sourmash::prelude::ToWriter;

Check failure on line 10 in src/core/tests/minhash.rs

View workflow job for this annotation

GitHub Actions / test (stable)

the name `ToWriter` is defined multiple times

Check warning on line 10 in src/core/tests/minhash.rs

View workflow job for this annotation

GitHub Actions / test (stable)

unused import: `sourmash::prelude::ToWriter`

Check failure on line 10 in src/core/tests/minhash.rs

View workflow job for this annotation

GitHub Actions / test (beta)

the name `ToWriter` is defined multiple times

Check warning on line 10 in src/core/tests/minhash.rs

View workflow job for this annotation

GitHub Actions / test (beta)

unused import: `sourmash::prelude::ToWriter`

Check failure on line 10 in src/core/tests/minhash.rs

View workflow job for this annotation

GitHub Actions / test (windows)

the name `ToWriter` is defined multiple times

Check warning on line 10 in src/core/tests/minhash.rs

View workflow job for this annotation

GitHub Actions / test (windows)

unused import: `sourmash::prelude::ToWriter`

Check failure on line 10 in src/core/tests/minhash.rs

View workflow job for this annotation

GitHub Actions / test (macos)

the name `ToWriter` is defined multiple times

Check warning on line 10 in src/core/tests/minhash.rs

View workflow job for this annotation

GitHub Actions / test (macos)

unused import: `sourmash::prelude::ToWriter`
use sourmash::signature::SeqToHashes;
use sourmash::signature::{Signature, SigsTrait};
use sourmash::sketch::minhash::{
max_hash_for_scaled, scaled_for_max_hash, KmerMinHash, KmerMinHashBTree,
};
use sourmash::sketch::Sketch;
use sourmash::ScaledType;
use sourmash::prelude::ToWriter;

// TODO: use f64::EPSILON when we bump MSRV
const EPSILON: f64 = 0.01;
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

0 comments on commit eb471c8

Please sign in to comment.