Skip to content

Object perf#20

Open
AvivDavid23 wants to merge 10 commits into
masterfrom
object_perf
Open

Object perf#20
AvivDavid23 wants to merge 10 commits into
masterfrom
object_perf

Conversation

@AvivDavid23

@AvivDavid23 AvivDavid23 commented Jul 1, 2026

Copy link
Copy Markdown

Object memory reduction (~20–40% per object container)

  • Pack IObject header 16B → 8B: {len:usize, cap:usize} → single u64 (32b len / 32b cap). Flat −8B per object.
  • Hash-table index usizeu32: table slots hold item indices (≤cap < 2^32), so 4B suffices. Halves table: 10·cap5·cap bytes.
  • Small-object no-table: objects with cap ≤ 8 store no hash table; lookups linear-scan the items array. Drops the table entirely for the common small object.
  • Net: −40% on tiny objects (table elided), −20% on larger ones (table halved), applied per-container down the whole tree.

API — fallible allocation

  • IObject mutators (with_capacity, insert, reserve, entry, …) now return Result<_, IJsonError>, mirroring IArray. Allocation failure and the 32-bit limit are recoverable instead of panicking.
  • Extend/FromIterator/From<HashMap|BTreeMap>TryExtend/TryFromIterator/TryFrom.
  • Moved the shared TryExtend/TryFromIterator/TryCollect traits into new src/convert.rs; pub use re-exports keep existing paths (ijson::array::TryExtend) working.
  • Infallible-context .unwrap()s (Clone, Drop/dealloc, layout, defrag, obj[k]=v) - they preserve the prior panic-on-OOM contract.

Compatibility

  • Breaking: a single IObject is now capped at 2^32−1 (~4.29B) entries (was usize) — the tradeoff for the packed 8B header + halved table. (IArray is unaffected; it keeps its pre-existing 2^32−1 cap from its own packed header.)

Note

High Risk
Rewrites core IObject storage, lookup, and resize behavior plus a breaking public API; incorrect hash/small-object logic would corrupt maps or lose keys.

Overview
IObject uses less memory per container by packing len/cap into an 8-byte header (was 16 bytes), storing hash-table slots as u32 instead of usize, and omitting the hash table when capacity ≤ 8 (linear scan only). Larger objects keep Robin-Hood probing but on the smaller table.

Breaking API: mutating IObject APIs (with_capacity, insert, reserve, entry, …) now return Result<_, IJsonError> like IArray, and infallible Extend/FromIterator/From<HashMap|BTreeMap> are replaced with TryExtend/TryFromIterator/TryFrom. Shared fallible iterator traits live in new src/convert.rs and are re-exported from the crate root (and still from array for compatibility). JSON/CBOR deserialize, serde serialize, and ijson! macros propagate allocation errors; internal paths that previously panicked on OOM still use .unwrap() where documented.

fuzz_object_ops is added to CI to fuzz insert/remove/get against a HashMap oracle, stressing small↔large table transitions and hash collisions.

Compatibility: max entries per object is now 2³²−1 (packed header tradeoff).

Reviewed by Cursor Bugbot for commit 0469d42. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1fface9. Configure here.

Comment thread src/value.rs
Comment thread src/object.rs
Comment thread src/object.rs
…, propagate ijson! insert errors

- From<HashMap|BTreeMap|Vec|&[..]> for IValue now panics on allocation
  failure instead of silently yielding IValue::NULL. Split the shared
  conversion macro: floats keep null-degradation (non-finite has no JSON
  representation); containers use a panicking variant, restoring the
  panic-on-OOM contract they had before the fallible API. TryFrom on the
  concrete container type remains the recoverable path.
- ijson! object arms now .unwrap() insert() instead of `let _ =`, matching
  the array arms — allocation failure panics rather than building a partial
  object.
…iner OOM, propagate ijson! insert errors"

This reverts commit 899c172.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant