Skip to content

Commit

Permalink
cargo update, profile, clippy, bloat misc
Browse files Browse the repository at this point in the history
  • Loading branch information
ijl committed Apr 30, 2024
1 parent 6ac2d2e commit cb0808d
Show file tree
Hide file tree
Showing 24 changed files with 310 additions and 312 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/artifact.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: artifact
on: push
env:
RUST_TOOLCHAIN: "nightly-2024-04-15"
RUST_TOOLCHAIN: "nightly-2024-04-30"
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
UNSAFE_PYO3_SKIP_VERSION_CHECK: "1"
jobs:
Expand Down Expand Up @@ -156,7 +156,7 @@ jobs:
LDFLAGS: "-Wl,--as-needed"
RUSTFLAGS: "-Z mir-opt-level=4 -Z threads=4 -D warnings -C target-feature=-crt-static"
with:
rust-toolchain: nightly-2024-04-15
rust-toolchain: nightly-2024-04-30
rustup-components: rust-src
target: ${{ matrix.platform.target }}
manylinux: musllinux_1_2
Expand Down Expand Up @@ -245,7 +245,7 @@ jobs:
RUSTFLAGS: "${{ matrix.target.rustflags }}"
with:
target: ${{ matrix.target.target }}
rust-toolchain: nightly-2024-04-15
rust-toolchain: nightly-2024-04-30
rustup-components: rust-src
manylinux: auto
args: --release --strip --out=dist --features=${{ matrix.target.features }} -i python${{ matrix.python.version }}
Expand Down Expand Up @@ -308,7 +308,7 @@ jobs:

- uses: dtolnay/rust-toolchain@master
with:
toolchain: "nightly-2024-04-15"
toolchain: "nightly-2024-04-30"
targets: "aarch64-apple-darwin, x86_64-apple-darwin"
components: "rust-src"

Expand Down Expand Up @@ -378,7 +378,7 @@ jobs:

- uses: dtolnay/rust-toolchain@master
with:
toolchain: "nightly-2024-04-15"
toolchain: "nightly-2024-04-30"
targets: "aarch64-apple-darwin, x86_64-apple-darwin"
components: "rust-src"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
profile: [
{ rust: "1.72", features: "" },
{ rust: "1.72", features: "--features=yyjson" },
{ rust: "nightly-2024-04-15", features: "--features=yyjson,unstable-simd" },
{ rust: "nightly-2024-04-30", features: "--features=yyjson,unstable-simd"},
]
python: [
{ version: '3.13' },
Expand Down
40 changes: 20 additions & 20 deletions Cargo.lock

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

34 changes: 17 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,24 @@ no-panic = [
yyjson = []

[dependencies]
ahash = { version = "^0.8.9", default_features = false, features = ["compile-time-rng"] }
arrayvec = { version = "0.7", default_features = false, features = ["std", "serde"] }
associative-cache = { version = "2", default_features = false }
beef = { version = "0.5", default_features = false, features = ["impl_serde"] }
bytecount = { version = "^0.6.7", default_features = false, features = ["runtime-dispatch-simd"] }
chrono = { version = "=0.4.34", default_features = false }
compact_str = { version = "0.7", default_features = false, features = ["serde"] }
encoding_rs = { version = "0.8", default_features = false }
half = { version = "2", default_features = false, features = ["std"] }
itoa = { version = "1", default_features = false }
ahash = { version = "^0.8.9", default-features = false, features = ["compile-time-rng"] }
arrayvec = { version = "0.7", default-features = false, features = ["std", "serde"] }
associative-cache = { version = "2", default-features = false }
beef = { version = "0.5", default-features = false, features = ["impl_serde"] }
bytecount = { version = "^0.6.7", default-features = false, features = ["runtime-dispatch-simd"] }
chrono = { version = "=0.4.34", default-features = false }
compact_str = { version = "0.7", default-features = false, features = ["serde"] }
encoding_rs = { version = "0.8", default-features = false }
half = { version = "2", default-features = false, features = ["std"] }
itoa = { version = "1", default-features = false }
itoap = { version = "1", features = ["std", "simd"] }
once_cell = { version = "1", default_features = false, features = ["race"] }
pyo3-ffi = { version = "^0.21", default_features = false, features = ["extension-module"]}
ryu = { version = "1", default_features = false }
serde = { version = "1", default_features = false }
serde_json = { version = "1", default_features = false, features = ["std", "float_roundtrip"] }
simdutf8 = { version = "0.1", default_features = false, features = ["std", "aarch64_neon"] }
smallvec = { version = "^1.11", default_features = false, features = ["union", "write"] }
once_cell = { version = "1", default-features = false, features = ["race"] }
pyo3-ffi = { version = "^0.21", default-features = false, features = ["extension-module"]}
ryu = { version = "1", default-features = false }
serde = { version = "1", default-features = false }
serde_json = { version = "1", default-features = false, features = ["std", "float_roundtrip"] }
simdutf8 = { version = "0.1", default-features = false, features = ["std", "aarch64_neon"] }
smallvec = { version = "^1.11", default-features = false, features = ["union", "write"] }

[build-dependencies]
cc = { version = "1" }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ It benefits from also having a C build environment to compile a faster
deserialization backend. See this project's `manylinux_2_28` builds for an
example using clang and LTO.

The project's own CI tests against `nightly-2024-04-15` and stable 1.72. It
The project's own CI tests against `nightly-2024-04-30` and stable 1.72. It
is prudent to pin the nightly version because that channel can introduce
breaking changes.

Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() {
}

#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
if !env::var("ORJSON_DISABLE_SIMD").is_ok() {
if env::var("ORJSON_DISABLE_SIMD").is_err() {
if let Some(true) = version_check::supports_feature("portable_simd") {
println!("cargo:rustc-cfg=feature=\"unstable-simd\"");
}
Expand Down
2 changes: 1 addition & 1 deletion ci/azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
variables:
toolchain: nightly-2024-04-15
toolchain: nightly-2024-04-30

jobs:

Expand Down
2 changes: 1 addition & 1 deletion script/pynumpy
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ elif kind == "float64":
array = numpy.random.random(size=(50000, 100))
assert array.dtype == numpy.float64
elif kind == "bool":
dtype = numpy.bool
dtype = numpy.bool_
array = numpy.random.choice((True, False), size=(100000, 200))
elif kind == "int8":
dtype = numpy.int8
Expand Down
5 changes: 5 additions & 0 deletions script/valgrind
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -eou pipefail

valgrind pytest -v --ignore=test/test_memory.py test
1 change: 1 addition & 0 deletions src/deserialize/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub type KeyMap =

pub static mut KEY_MAP: OnceCell<KeyMap> = OnceCell::new();

#[inline(always)]
pub fn cache_hash(key: &[u8]) -> u64 {
// try to omit code for >64 path in ahash
assume!(key.len() <= 64);
Expand Down
3 changes: 1 addition & 2 deletions src/deserialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod json;
#[cfg(feature = "yyjson")]
mod yyjson;

pub use cache::KeyMap;
pub use cache::KEY_MAP;
pub use cache::{KeyMap, KEY_MAP};
pub use deserializer::deserialize;
pub use error::DeserializeError;
48 changes: 22 additions & 26 deletions src/deserialize/pyobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,30 @@ use crate::str::{hash_str, unicode_from_str};
use crate::typeref::{FALSE, NONE, TRUE};
use core::ptr::NonNull;

#[inline(always)]
pub fn get_unicode_key(key_str: &str) -> *mut pyo3_ffi::PyObject {
let pykey = if unlikely!(key_str.len() > 64) {
create_str_impl(key_str)
if unlikely!(key_str.len() > 64) {
let pyob = unicode_from_str(key_str);
hash_str(pyob);
pyob
} else {
get_unicode_key_impl(key_str)
};
debug_assert!(ffi!(Py_REFCNT(pykey)) >= 1);
debug_assert!(unsafe { (*pykey.cast::<pyo3_ffi::PyASCIIObject>()).hash != -1 });
pykey
}

fn get_unicode_key_impl(key_str: &str) -> *mut pyo3_ffi::PyObject {
let hash = cache_hash(key_str.as_bytes());
let map = unsafe { KEY_MAP.get_mut().unwrap_or_else(|| unreachable!()) };
let entry = map.entry(&hash).or_insert_with(
|| hash,
|| {
let pyob = create_str_impl(key_str);
CachedKey::new(pyob)
},
);
entry.get()
}

fn create_str_impl(key_str: &str) -> *mut pyo3_ffi::PyObject {
let pyob = unicode_from_str(key_str);
hash_str(pyob);
pyob
let hash = cache_hash(key_str.as_bytes());
unsafe {
let entry = KEY_MAP
.get_mut()
.unwrap_or_else(|| unreachable!())
.entry(&hash)
.or_insert_with(
|| hash,
|| {
let pyob = unicode_from_str(key_str);
hash_str(pyob);
CachedKey::new(pyob)
},
);
entry.get()
}
}
}

#[allow(dead_code)]
Expand Down
12 changes: 8 additions & 4 deletions src/serialize/per_type/dataclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ impl DataclassFastSerializer {
}

impl Serialize for DataclassFastSerializer {
#[inline(never)]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand All @@ -92,12 +93,13 @@ impl Serialize for DataclassFastSerializer {
return ZeroDictSerializer::new().serialize(serializer);
}
let mut map = serializer.serialize_map(None).unwrap();
let mut next_key: *mut pyo3_ffi::PyObject = core::ptr::null_mut();
let mut next_value: *mut pyo3_ffi::PyObject = core::ptr::null_mut();

let mut pos = 0;
let mut next_key: *mut pyo3_ffi::PyObject = core::ptr::null_mut();
let mut next_value: *mut pyo3_ffi::PyObject = core::ptr::null_mut();

pydict_next!(self.ptr, &mut pos, &mut next_key, &mut next_value);

for _ in 0..ffi!(Py_SIZE(self.ptr)) as usize {
let key = next_key;
let value = next_value;
Expand Down Expand Up @@ -144,6 +146,8 @@ impl DataclassFallbackSerializer {
}

impl Serialize for DataclassFallbackSerializer {
#[cold]
#[inline(never)]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
Expand All @@ -157,12 +161,12 @@ impl Serialize for DataclassFallbackSerializer {
}
let mut map = serializer.serialize_map(None).unwrap();

let mut pos = 0;
let mut next_key: *mut pyo3_ffi::PyObject = core::ptr::null_mut();
let mut next_value: *mut pyo3_ffi::PyObject = core::ptr::null_mut();

let mut pos = 0;

pydict_next!(fields, &mut pos, &mut next_key, &mut next_value);

for _ in 0..ffi!(Py_SIZE(fields)) as usize {
let attr = next_key;
let field = next_value;
Expand Down
Loading

0 comments on commit cb0808d

Please sign in to comment.