Skip to content

Commit c89e6d5

Browse files
committed
cargo update, profile, clippy, bloat misc
1 parent 6ac2d2e commit c89e6d5

25 files changed

+311
-313
lines changed

.github/workflows/artifact.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: artifact
22
on: push
33
env:
4-
RUST_TOOLCHAIN: "nightly-2024-04-15"
4+
RUST_TOOLCHAIN: "nightly-2024-04-30"
55
CARGO_UNSTABLE_SPARSE_REGISTRY: "true"
66
UNSAFE_PYO3_SKIP_VERSION_CHECK: "1"
77
jobs:
@@ -156,7 +156,7 @@ jobs:
156156
LDFLAGS: "-Wl,--as-needed"
157157
RUSTFLAGS: "-Z mir-opt-level=4 -Z threads=4 -D warnings -C target-feature=-crt-static"
158158
with:
159-
rust-toolchain: nightly-2024-04-15
159+
rust-toolchain: nightly-2024-04-30
160160
rustup-components: rust-src
161161
target: ${{ matrix.platform.target }}
162162
manylinux: musllinux_1_2
@@ -245,7 +245,7 @@ jobs:
245245
RUSTFLAGS: "${{ matrix.target.rustflags }}"
246246
with:
247247
target: ${{ matrix.target.target }}
248-
rust-toolchain: nightly-2024-04-15
248+
rust-toolchain: nightly-2024-04-30
249249
rustup-components: rust-src
250250
manylinux: auto
251251
args: --release --strip --out=dist --features=${{ matrix.target.features }} -i python${{ matrix.python.version }}
@@ -308,7 +308,7 @@ jobs:
308308

309309
- uses: dtolnay/rust-toolchain@master
310310
with:
311-
toolchain: "nightly-2024-04-15"
311+
toolchain: "nightly-2024-04-30"
312312
targets: "aarch64-apple-darwin, x86_64-apple-darwin"
313313
components: "rust-src"
314314

@@ -378,7 +378,7 @@ jobs:
378378

379379
- uses: dtolnay/rust-toolchain@master
380380
with:
381-
toolchain: "nightly-2024-04-15"
381+
toolchain: "nightly-2024-04-30"
382382
targets: "aarch64-apple-darwin, x86_64-apple-darwin"
383383
components: "rust-src"
384384

.github/workflows/debug.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
profile: [
1111
{ rust: "1.72", features: "" },
1212
{ rust: "1.72", features: "--features=yyjson" },
13-
{ rust: "nightly-2024-04-15", features: "--features=yyjson,unstable-simd" },
13+
{ rust: "nightly-2024-04-30", features: "--features=yyjson,unstable-simd"},
1414
]
1515
python: [
1616
{ version: '3.13' },

Cargo.lock

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

Cargo.toml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ no-panic = [
4545
yyjson = []
4646

4747
[dependencies]
48-
ahash = { version = "^0.8.9", default_features = false, features = ["compile-time-rng"] }
49-
arrayvec = { version = "0.7", default_features = false, features = ["std", "serde"] }
50-
associative-cache = { version = "2", default_features = false }
51-
beef = { version = "0.5", default_features = false, features = ["impl_serde"] }
52-
bytecount = { version = "^0.6.7", default_features = false, features = ["runtime-dispatch-simd"] }
53-
chrono = { version = "=0.4.34", default_features = false }
54-
compact_str = { version = "0.7", default_features = false, features = ["serde"] }
55-
encoding_rs = { version = "0.8", default_features = false }
56-
half = { version = "2", default_features = false, features = ["std"] }
57-
itoa = { version = "1", default_features = false }
48+
ahash = { version = "^0.8.9", default-features = false, features = ["compile-time-rng"] }
49+
arrayvec = { version = "0.7", default-features = false, features = ["std", "serde"] }
50+
associative-cache = { version = "2", default-features = false }
51+
beef = { version = "0.5", default-features = false, features = ["impl_serde"] }
52+
bytecount = { version = "^0.6.7", default-features = false, features = ["runtime-dispatch-simd"] }
53+
chrono = { version = "=0.4.34", default-features = false }
54+
compact_str = { version = "0.7", default-features = false, features = ["serde"] }
55+
encoding_rs = { version = "0.8", default-features = false }
56+
half = { version = "2", default-features = false, features = ["std"] }
57+
itoa = { version = "1", default-features = false }
5858
itoap = { version = "1", features = ["std", "simd"] }
59-
once_cell = { version = "1", default_features = false, features = ["race"] }
60-
pyo3-ffi = { version = "^0.21", default_features = false, features = ["extension-module"]}
61-
ryu = { version = "1", default_features = false }
62-
serde = { version = "1", default_features = false }
63-
serde_json = { version = "1", default_features = false, features = ["std", "float_roundtrip"] }
64-
simdutf8 = { version = "0.1", default_features = false, features = ["std", "aarch64_neon"] }
65-
smallvec = { version = "^1.11", default_features = false, features = ["union", "write"] }
59+
once_cell = { version = "1", default-features = false, features = ["race"] }
60+
pyo3-ffi = { version = "^0.21", default-features = false, features = ["extension-module"]}
61+
ryu = { version = "1", default-features = false }
62+
serde = { version = "1", default-features = false }
63+
serde_json = { version = "1", default-features = false, features = ["std", "float_roundtrip"] }
64+
simdutf8 = { version = "0.1", default-features = false, features = ["std", "aarch64_neon"] }
65+
smallvec = { version = "^1.11", default-features = false, features = ["union", "write"] }
6666

6767
[build-dependencies]
6868
cc = { version = "1" }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ It benefits from also having a C build environment to compile a faster
12031203
deserialization backend. See this project's `manylinux_2_28` builds for an
12041204
example using clang and LTO.
12051205

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

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn main() {
2929
}
3030

3131
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
32-
if !env::var("ORJSON_DISABLE_SIMD").is_ok() {
32+
if env::var("ORJSON_DISABLE_SIMD").is_err() {
3333
if let Some(true) = version_check::supports_feature("portable_simd") {
3434
println!("cargo:rustc-cfg=feature=\"unstable-simd\"");
3535
}

ci/azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
variables:
2-
toolchain: nightly-2024-04-15
2+
toolchain: nightly-2024-04-30
33

44
jobs:
55

script/pynumpy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ elif kind == "float64":
3535
array = numpy.random.random(size=(50000, 100))
3636
assert array.dtype == numpy.float64
3737
elif kind == "bool":
38-
dtype = numpy.bool
38+
dtype = numpy.bool_
3939
array = numpy.random.choice((True, False), size=(100000, 200))
4040
elif kind == "int8":
4141
dtype = numpy.int8

script/valgrind

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
set -eou pipefail
4+
5+
valgrind pytest -v --ignore=test/test_memory.py test

src/deserialize/cache.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub type KeyMap =
3838

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

41+
#[inline(always)]
4142
pub fn cache_hash(key: &[u8]) -> u64 {
4243
// try to omit code for >64 path in ahash
4344
assume!(key.len() <= 64);

src/deserialize/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ mod json;
1212
#[cfg(feature = "yyjson")]
1313
mod yyjson;
1414

15-
pub use cache::KeyMap;
16-
pub use cache::KEY_MAP;
15+
pub use cache::{KeyMap, KEY_MAP};
1716
pub use deserializer::deserialize;
1817
pub use error::DeserializeError;

src/deserialize/pyobject.rs

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,30 @@ use crate::str::{hash_str, unicode_from_str};
55
use crate::typeref::{FALSE, NONE, TRUE};
66
use core::ptr::NonNull;
77

8+
#[inline(always)]
89
pub fn get_unicode_key(key_str: &str) -> *mut pyo3_ffi::PyObject {
9-
let pykey = if unlikely!(key_str.len() > 64) {
10-
create_str_impl(key_str)
10+
if unlikely!(key_str.len() > 64) {
11+
let pyob = unicode_from_str(key_str);
12+
hash_str(pyob);
13+
pyob
1114
} else {
12-
get_unicode_key_impl(key_str)
13-
};
14-
debug_assert!(ffi!(Py_REFCNT(pykey)) >= 1);
15-
debug_assert!(unsafe { (*pykey.cast::<pyo3_ffi::PyASCIIObject>()).hash != -1 });
16-
pykey
17-
}
18-
19-
fn get_unicode_key_impl(key_str: &str) -> *mut pyo3_ffi::PyObject {
20-
let hash = cache_hash(key_str.as_bytes());
21-
let map = unsafe { KEY_MAP.get_mut().unwrap_or_else(|| unreachable!()) };
22-
let entry = map.entry(&hash).or_insert_with(
23-
|| hash,
24-
|| {
25-
let pyob = create_str_impl(key_str);
26-
CachedKey::new(pyob)
27-
},
28-
);
29-
entry.get()
30-
}
31-
32-
fn create_str_impl(key_str: &str) -> *mut pyo3_ffi::PyObject {
33-
let pyob = unicode_from_str(key_str);
34-
hash_str(pyob);
35-
pyob
15+
let hash = cache_hash(key_str.as_bytes());
16+
unsafe {
17+
let entry = KEY_MAP
18+
.get_mut()
19+
.unwrap_or_else(|| unreachable!())
20+
.entry(&hash)
21+
.or_insert_with(
22+
|| hash,
23+
|| {
24+
let pyob = unicode_from_str(key_str);
25+
hash_str(pyob);
26+
CachedKey::new(pyob)
27+
},
28+
);
29+
entry.get()
30+
}
31+
}
3632
}
3733

3834
#[allow(dead_code)]

src/serialize/per_type/dataclass.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl DataclassFastSerializer {
8383
}
8484

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

9897
let mut pos = 0;
98+
let mut next_key: *mut pyo3_ffi::PyObject = core::ptr::null_mut();
99+
let mut next_value: *mut pyo3_ffi::PyObject = core::ptr::null_mut();
99100

100101
pydict_next!(self.ptr, &mut pos, &mut next_key, &mut next_value);
102+
101103
for _ in 0..ffi!(Py_SIZE(self.ptr)) as usize {
102104
let key = next_key;
103105
let value = next_value;
@@ -144,6 +146,8 @@ impl DataclassFallbackSerializer {
144146
}
145147

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

164+
let mut pos = 0;
160165
let mut next_key: *mut pyo3_ffi::PyObject = core::ptr::null_mut();
161166
let mut next_value: *mut pyo3_ffi::PyObject = core::ptr::null_mut();
162167

163-
let mut pos = 0;
164-
165168
pydict_next!(fields, &mut pos, &mut next_key, &mut next_value);
169+
166170
for _ in 0..ffi!(Py_SIZE(fields)) as usize {
167171
let attr = next_key;
168172
let field = next_value;

0 commit comments

Comments
 (0)