weaved 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- weaved-0.1.0/.github/workflows/ci.yml +123 -0
- weaved-0.1.0/.gitignore +13 -0
- weaved-0.1.0/Cargo.lock +132 -0
- weaved-0.1.0/Cargo.toml +19 -0
- weaved-0.1.0/PKG-INFO +110 -0
- weaved-0.1.0/README.md +95 -0
- weaved-0.1.0/asv.conf.json +17 -0
- weaved-0.1.0/benchmarks/README.md +35 -0
- weaved-0.1.0/benchmarks/asv/__init__.py +0 -0
- weaved-0.1.0/benchmarks/asv/bench_merge.py +154 -0
- weaved-0.1.0/pyproject.toml +46 -0
- weaved-0.1.0/python/weave/__init__.py +5 -0
- weaved-0.1.0/python/weave/_weave.pyi +7 -0
- weaved-0.1.0/python/weave/py.typed +0 -0
- weaved-0.1.0/src/lib.rs +29 -0
- weaved-0.1.0/src/merge.rs +109 -0
- weaved-0.1.0/src/recursion.rs +34 -0
- weaved-0.1.0/tests/test_merge.py +284 -0
- weaved-0.1.0/tests/test_properties.py +74 -0
- weaved-0.1.0/uv.lock +476 -0
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
push:
|
|
6
|
+
branches: ["**"]
|
|
7
|
+
tags:
|
|
8
|
+
- "v*"
|
|
9
|
+
pull_request:
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
test:
|
|
16
|
+
strategy:
|
|
17
|
+
fail-fast: false
|
|
18
|
+
matrix:
|
|
19
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
20
|
+
python: ["3.11", "3.14"]
|
|
21
|
+
runs-on: ${{ matrix.os }}
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v7
|
|
24
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
25
|
+
with:
|
|
26
|
+
components: rustfmt, clippy
|
|
27
|
+
- uses: astral-sh/setup-uv@v10.2.0
|
|
28
|
+
with:
|
|
29
|
+
python-version: ${{ matrix.python }}
|
|
30
|
+
- run: uv sync --locked
|
|
31
|
+
- run: uv run --no-sync pytest
|
|
32
|
+
- run: uv run --no-sync ruff check .
|
|
33
|
+
- run: uv run --no-sync ruff format --check .
|
|
34
|
+
- run: cargo fmt --check
|
|
35
|
+
- run: uv run --no-sync -- cargo clippy --locked --all-targets -- -D warnings
|
|
36
|
+
- run: uv run --no-sync maturin build --release --locked
|
|
37
|
+
if: matrix.os != 'ubuntu-latest'
|
|
38
|
+
- uses: PyO3/maturin-action@v1.51.0
|
|
39
|
+
if: matrix.os == 'ubuntu-latest'
|
|
40
|
+
with:
|
|
41
|
+
maturin-version: 1.15.0
|
|
42
|
+
manylinux: "2_28"
|
|
43
|
+
args: --release --locked -i python${{ matrix.python }} --compatibility pypi --out target/wheels
|
|
44
|
+
- uses: actions/upload-artifact@v7
|
|
45
|
+
if: matrix.os != 'ubuntu-latest'
|
|
46
|
+
with:
|
|
47
|
+
name: wheel-${{ matrix.os }}-py${{ matrix.python }}
|
|
48
|
+
path: target/wheels/*.whl
|
|
49
|
+
- uses: actions/upload-artifact@v7
|
|
50
|
+
if: matrix.os == 'ubuntu-latest'
|
|
51
|
+
with:
|
|
52
|
+
name: wheel-${{ matrix.os }}-py${{ matrix.python }}
|
|
53
|
+
path: target/wheels/*manylinux*.whl
|
|
54
|
+
|
|
55
|
+
performance:
|
|
56
|
+
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/master'
|
|
57
|
+
runs-on: ubuntu-latest
|
|
58
|
+
steps:
|
|
59
|
+
- uses: actions/checkout@v7
|
|
60
|
+
with:
|
|
61
|
+
fetch-depth: 0
|
|
62
|
+
- uses: actions/setup-python@v6
|
|
63
|
+
with:
|
|
64
|
+
python-version: "3.14"
|
|
65
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
66
|
+
- uses: astral-sh/setup-uv@v10.2.0
|
|
67
|
+
- run: uv sync --locked
|
|
68
|
+
- name: Register benchmark runner
|
|
69
|
+
run: |
|
|
70
|
+
os_name="$(. /etc/os-release && echo "$PRETTY_NAME")"
|
|
71
|
+
cpu="$(lscpu | awk -F: '/Model name/ {gsub(/^[[:space:]]+/, "", $2); print $2; exit}')"
|
|
72
|
+
ram="$(awk '/MemTotal/ {printf "%.0fGB", $2 / 1048576}' /proc/meminfo)"
|
|
73
|
+
uv run asv machine --yes \
|
|
74
|
+
--machine "github-${RUNNER_OS}-${RUNNER_ARCH}" \
|
|
75
|
+
--os "$os_name" \
|
|
76
|
+
--arch "$(uname -m)" \
|
|
77
|
+
--cpu "$cpu" \
|
|
78
|
+
--num_cpu "$(nproc)" \
|
|
79
|
+
--ram "$ram"
|
|
80
|
+
- name: Compare base and proposed revision
|
|
81
|
+
env:
|
|
82
|
+
BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
|
|
83
|
+
HEAD: ${{ github.sha }}
|
|
84
|
+
run: uv run asv continuous --factor 1.15 --interleave-rounds --split "$BASE" "$HEAD"
|
|
85
|
+
- uses: actions/upload-artifact@v7
|
|
86
|
+
if: always()
|
|
87
|
+
with:
|
|
88
|
+
name: asv-results-${{ github.run_id }}
|
|
89
|
+
path: .asv/results
|
|
90
|
+
if-no-files-found: ignore
|
|
91
|
+
|
|
92
|
+
sdist:
|
|
93
|
+
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
|
|
94
|
+
runs-on: ubuntu-latest
|
|
95
|
+
steps:
|
|
96
|
+
- uses: actions/checkout@v7
|
|
97
|
+
- uses: astral-sh/setup-uv@v10.2.0
|
|
98
|
+
- run: uv build --sdist
|
|
99
|
+
- uses: actions/upload-artifact@v7
|
|
100
|
+
with:
|
|
101
|
+
name: source-distribution
|
|
102
|
+
path: dist/*
|
|
103
|
+
|
|
104
|
+
publish:
|
|
105
|
+
if: github.event_name == 'workflow_dispatch' || startsWith(github.ref, 'refs/tags/v')
|
|
106
|
+
needs: [test, sdist]
|
|
107
|
+
runs-on: ubuntu-latest
|
|
108
|
+
environment:
|
|
109
|
+
name: pypi
|
|
110
|
+
url: https://pypi.org/project/weaved/
|
|
111
|
+
permissions:
|
|
112
|
+
id-token: write
|
|
113
|
+
steps:
|
|
114
|
+
- uses: actions/download-artifact@v8.0.1
|
|
115
|
+
with:
|
|
116
|
+
pattern: "wheel-*"
|
|
117
|
+
path: dist
|
|
118
|
+
merge-multiple: true
|
|
119
|
+
- uses: actions/download-artifact@v8.0.1
|
|
120
|
+
with:
|
|
121
|
+
name: source-distribution
|
|
122
|
+
path: dist
|
|
123
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
weaved-0.1.0/.gitignore
ADDED
weaved-0.1.0/Cargo.lock
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "heck"
|
|
7
|
+
version = "0.5.0"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "libc"
|
|
13
|
+
version = "0.2.189"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "once_cell"
|
|
19
|
+
version = "1.21.4"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "portable-atomic"
|
|
25
|
+
version = "1.15.0"
|
|
26
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
+
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
|
28
|
+
|
|
29
|
+
[[package]]
|
|
30
|
+
name = "proc-macro2"
|
|
31
|
+
version = "1.0.107"
|
|
32
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
33
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
34
|
+
dependencies = [
|
|
35
|
+
"unicode-ident",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[[package]]
|
|
39
|
+
name = "pyo3"
|
|
40
|
+
version = "0.29.3"
|
|
41
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
42
|
+
checksum = "700d18fa267b73b9b521fd7e13580e2f446916f176cacee1ab63fcc8191f1655"
|
|
43
|
+
dependencies = [
|
|
44
|
+
"libc",
|
|
45
|
+
"once_cell",
|
|
46
|
+
"portable-atomic",
|
|
47
|
+
"pyo3-build-config",
|
|
48
|
+
"pyo3-ffi",
|
|
49
|
+
"pyo3-macros",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[[package]]
|
|
53
|
+
name = "pyo3-build-config"
|
|
54
|
+
version = "0.29.3"
|
|
55
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
56
|
+
checksum = "7b3fc0c4d08f6bb10e71fe39dfb9e2f59c6eb6854e22ec8092f50c69a4499adb"
|
|
57
|
+
dependencies = [
|
|
58
|
+
"target-lexicon",
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
[[package]]
|
|
62
|
+
name = "pyo3-ffi"
|
|
63
|
+
version = "0.29.3"
|
|
64
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
65
|
+
checksum = "dfc0b8e19df29aad7086cf977bb0c2a2f143e30567eb113e9cf72b62ca698330"
|
|
66
|
+
dependencies = [
|
|
67
|
+
"libc",
|
|
68
|
+
"pyo3-build-config",
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
[[package]]
|
|
72
|
+
name = "pyo3-macros"
|
|
73
|
+
version = "0.29.3"
|
|
74
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
75
|
+
checksum = "6100e8a4b5eba53afaa5ed078364851a0b2499c553a44c31026b929049b49dc6"
|
|
76
|
+
dependencies = [
|
|
77
|
+
"proc-macro2",
|
|
78
|
+
"pyo3-macros-backend",
|
|
79
|
+
"quote",
|
|
80
|
+
"syn",
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
[[package]]
|
|
84
|
+
name = "pyo3-macros-backend"
|
|
85
|
+
version = "0.29.3"
|
|
86
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
87
|
+
checksum = "6143877a16e82b5a727b7127ff4cd86858a24a28d745d72f43e6f227c7b1bdb3"
|
|
88
|
+
dependencies = [
|
|
89
|
+
"heck",
|
|
90
|
+
"proc-macro2",
|
|
91
|
+
"quote",
|
|
92
|
+
"syn",
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
[[package]]
|
|
96
|
+
name = "quote"
|
|
97
|
+
version = "1.0.47"
|
|
98
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
99
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
100
|
+
dependencies = [
|
|
101
|
+
"proc-macro2",
|
|
102
|
+
]
|
|
103
|
+
|
|
104
|
+
[[package]]
|
|
105
|
+
name = "syn"
|
|
106
|
+
version = "2.0.119"
|
|
107
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
108
|
+
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
|
109
|
+
dependencies = [
|
|
110
|
+
"proc-macro2",
|
|
111
|
+
"quote",
|
|
112
|
+
"unicode-ident",
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
[[package]]
|
|
116
|
+
name = "target-lexicon"
|
|
117
|
+
version = "0.13.5"
|
|
118
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
119
|
+
checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca"
|
|
120
|
+
|
|
121
|
+
[[package]]
|
|
122
|
+
name = "unicode-ident"
|
|
123
|
+
version = "1.0.26"
|
|
124
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
125
|
+
checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
|
|
126
|
+
|
|
127
|
+
[[package]]
|
|
128
|
+
name = "weave"
|
|
129
|
+
version = "0.1.0"
|
|
130
|
+
dependencies = [
|
|
131
|
+
"pyo3",
|
|
132
|
+
]
|
weaved-0.1.0/Cargo.toml
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "weave"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
rust-version = "1.85"
|
|
6
|
+
description = "Fast, non-mutating deep merges for Python dictionaries"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
repository = "https://github.com/cetanu/weaved"
|
|
9
|
+
|
|
10
|
+
[lib]
|
|
11
|
+
name = "_weave"
|
|
12
|
+
crate-type = ["cdylib"]
|
|
13
|
+
|
|
14
|
+
[dependencies]
|
|
15
|
+
pyo3 = "0.29.3"
|
|
16
|
+
|
|
17
|
+
[profile.release]
|
|
18
|
+
lto = "thin"
|
|
19
|
+
codegen-units = 1
|
weaved-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: weaved
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Classifier: Development Status :: 3 - Alpha
|
|
5
|
+
Classifier: Programming Language :: Rust
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
8
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
9
|
+
Classifier: Typing :: Typed
|
|
10
|
+
Summary: Fast, non-mutating deep merges for Python dictionaries
|
|
11
|
+
Requires-Python: >=3.11
|
|
12
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
13
|
+
Project-URL: Repository, https://github.com/cetanu/weaved
|
|
14
|
+
|
|
15
|
+
# Weave
|
|
16
|
+
|
|
17
|
+
A Rust-backed Python library for merging nested dictionaries. One function,
|
|
18
|
+
no runtime Python dependencies, and no mutation of your inputs.
|
|
19
|
+
|
|
20
|
+
Install the `weaved` distribution from PyPI:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
python -m pip install weaved
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
The import package remains `weave`. Installing from source requires Rust; the
|
|
27
|
+
extension uses [PyO3](https://pyo3.rs/) and is built with
|
|
28
|
+
[maturin](https://www.maturin.rs/).
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from weave import merge
|
|
32
|
+
|
|
33
|
+
defaults = {"server": {"host": "localhost", "port": 8000}, "plugins": ["logging"]}
|
|
34
|
+
overrides = {"server": {"port": 9000}, "plugins": ["metrics"]}
|
|
35
|
+
|
|
36
|
+
merge(defaults, overrides)
|
|
37
|
+
# {"server": {"host": "localhost", "port": 9000}, "plugins": ["metrics"]}
|
|
38
|
+
|
|
39
|
+
merge(defaults, overrides, concat_lists=True)
|
|
40
|
+
# {"server": {"host": "localhost", "port": 9000}, "plugins": ["logging", "metrics"]}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Merge semantics
|
|
44
|
+
|
|
45
|
+
`merge(left, right, *, concat_lists=False) -> dict`
|
|
46
|
+
|
|
47
|
+
- Both arguments must be dictionaries (subclasses are accepted).
|
|
48
|
+
- When both values at a key are dictionaries, merge them recursively.
|
|
49
|
+
- Otherwise the right value replaces the left, including `None` and empty values.
|
|
50
|
+
- With `concat_lists=True`, two lists concatenate in left-to-right order at
|
|
51
|
+
every dictionary depth. Duplicates remain; elements are not merged by index.
|
|
52
|
+
- Every dictionary and list reached through dictionary values or list elements
|
|
53
|
+
is copied. Changing those containers in the result does not change either input.
|
|
54
|
+
Container subclasses become plain dictionaries and lists, using their stored
|
|
55
|
+
contents rather than overridden Python methods.
|
|
56
|
+
- Keys and other objects (including tuples, sets, and custom instances) retain
|
|
57
|
+
their identity. Weave does not traverse them or call `__deepcopy__`.
|
|
58
|
+
For example, a list inside an opaque tuple remains shared.
|
|
59
|
+
- Repeated references to the same container are copied separately; alias
|
|
60
|
+
relationships are not preserved.
|
|
61
|
+
- Existing keys retain their left-hand insertion order. New keys are appended
|
|
62
|
+
in right-hand order. All hashable Python keys are supported.
|
|
63
|
+
- Traversed cycles or more than 256 nested dictionary/list levels raise
|
|
64
|
+
`RecursionError`; Python's own stack guard can stop traversal earlier.
|
|
65
|
+
Overwritten values are not traversed.
|
|
66
|
+
- Exceptions from key hashing or equality propagate. Inputs must not be mutated
|
|
67
|
+
during a merge, including from key callbacks.
|
|
68
|
+
|
|
69
|
+
## Development
|
|
70
|
+
|
|
71
|
+
Requires CPython 3.11+ and Rust 1.85+ to build from source. Native wheels do not
|
|
72
|
+
require Rust. The extension uses the full Python API for performance, so wheels
|
|
73
|
+
are specific to a Python version. It holds the GIL while accessing Python objects.
|
|
74
|
+
|
|
75
|
+
```sh
|
|
76
|
+
uv sync
|
|
77
|
+
uv run pytest
|
|
78
|
+
uv run ruff check .
|
|
79
|
+
cargo fmt --check
|
|
80
|
+
cargo clippy --all-targets -- -D warnings
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`uv sync` builds the extension in release mode. After editing Rust, rebuild it
|
|
84
|
+
with `uv run maturin develop --release` before testing. Build distribution
|
|
85
|
+
artifacts with `uv run maturin build --release` and `uv run maturin sdist`.
|
|
86
|
+
|
|
87
|
+
## Performance
|
|
88
|
+
|
|
89
|
+
The merge walks Python containers directly through PyO3, with native dictionary
|
|
90
|
+
copies and list concatenation. Scalar leaves stay as Python objects; there is no
|
|
91
|
+
JSON encoding, deserialization, or conversion to Rust maps.
|
|
92
|
+
|
|
93
|
+
Run the Airspeed Velocity benchmarks against an equivalent Python implementation:
|
|
94
|
+
|
|
95
|
+
```sh
|
|
96
|
+
uv sync
|
|
97
|
+
uv run asv continuous --factor 1.15 --interleave-rounds --split HEAD^ HEAD
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Benchmarks check matching results before timing and cover flat dictionaries,
|
|
101
|
+
nested configuration, deep dictionaries, large lists, and list concatenation.
|
|
102
|
+
Both implementations copy dict/list containers and share opaque leaves. ASV
|
|
103
|
+
stores results in `.asv/results`; CI compares each pull request against its base
|
|
104
|
+
revision on the same runner and uploads the result files as a workflow artifact.
|
|
105
|
+
The 15% threshold filters small variations. Use release builds and measure your
|
|
106
|
+
own workload; Python allocation and key hashing still determine much of the cost.
|
|
107
|
+
|
|
108
|
+
See [local benchmark results](benchmarks/README.md) for measured timings and
|
|
109
|
+
the machine and sampling conditions.
|
|
110
|
+
|
weaved-0.1.0/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Weave
|
|
2
|
+
|
|
3
|
+
A Rust-backed Python library for merging nested dictionaries. One function,
|
|
4
|
+
no runtime Python dependencies, and no mutation of your inputs.
|
|
5
|
+
|
|
6
|
+
Install the `weaved` distribution from PyPI:
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
python -m pip install weaved
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The import package remains `weave`. Installing from source requires Rust; the
|
|
13
|
+
extension uses [PyO3](https://pyo3.rs/) and is built with
|
|
14
|
+
[maturin](https://www.maturin.rs/).
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from weave import merge
|
|
18
|
+
|
|
19
|
+
defaults = {"server": {"host": "localhost", "port": 8000}, "plugins": ["logging"]}
|
|
20
|
+
overrides = {"server": {"port": 9000}, "plugins": ["metrics"]}
|
|
21
|
+
|
|
22
|
+
merge(defaults, overrides)
|
|
23
|
+
# {"server": {"host": "localhost", "port": 9000}, "plugins": ["metrics"]}
|
|
24
|
+
|
|
25
|
+
merge(defaults, overrides, concat_lists=True)
|
|
26
|
+
# {"server": {"host": "localhost", "port": 9000}, "plugins": ["logging", "metrics"]}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Merge semantics
|
|
30
|
+
|
|
31
|
+
`merge(left, right, *, concat_lists=False) -> dict`
|
|
32
|
+
|
|
33
|
+
- Both arguments must be dictionaries (subclasses are accepted).
|
|
34
|
+
- When both values at a key are dictionaries, merge them recursively.
|
|
35
|
+
- Otherwise the right value replaces the left, including `None` and empty values.
|
|
36
|
+
- With `concat_lists=True`, two lists concatenate in left-to-right order at
|
|
37
|
+
every dictionary depth. Duplicates remain; elements are not merged by index.
|
|
38
|
+
- Every dictionary and list reached through dictionary values or list elements
|
|
39
|
+
is copied. Changing those containers in the result does not change either input.
|
|
40
|
+
Container subclasses become plain dictionaries and lists, using their stored
|
|
41
|
+
contents rather than overridden Python methods.
|
|
42
|
+
- Keys and other objects (including tuples, sets, and custom instances) retain
|
|
43
|
+
their identity. Weave does not traverse them or call `__deepcopy__`.
|
|
44
|
+
For example, a list inside an opaque tuple remains shared.
|
|
45
|
+
- Repeated references to the same container are copied separately; alias
|
|
46
|
+
relationships are not preserved.
|
|
47
|
+
- Existing keys retain their left-hand insertion order. New keys are appended
|
|
48
|
+
in right-hand order. All hashable Python keys are supported.
|
|
49
|
+
- Traversed cycles or more than 256 nested dictionary/list levels raise
|
|
50
|
+
`RecursionError`; Python's own stack guard can stop traversal earlier.
|
|
51
|
+
Overwritten values are not traversed.
|
|
52
|
+
- Exceptions from key hashing or equality propagate. Inputs must not be mutated
|
|
53
|
+
during a merge, including from key callbacks.
|
|
54
|
+
|
|
55
|
+
## Development
|
|
56
|
+
|
|
57
|
+
Requires CPython 3.11+ and Rust 1.85+ to build from source. Native wheels do not
|
|
58
|
+
require Rust. The extension uses the full Python API for performance, so wheels
|
|
59
|
+
are specific to a Python version. It holds the GIL while accessing Python objects.
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
uv sync
|
|
63
|
+
uv run pytest
|
|
64
|
+
uv run ruff check .
|
|
65
|
+
cargo fmt --check
|
|
66
|
+
cargo clippy --all-targets -- -D warnings
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`uv sync` builds the extension in release mode. After editing Rust, rebuild it
|
|
70
|
+
with `uv run maturin develop --release` before testing. Build distribution
|
|
71
|
+
artifacts with `uv run maturin build --release` and `uv run maturin sdist`.
|
|
72
|
+
|
|
73
|
+
## Performance
|
|
74
|
+
|
|
75
|
+
The merge walks Python containers directly through PyO3, with native dictionary
|
|
76
|
+
copies and list concatenation. Scalar leaves stay as Python objects; there is no
|
|
77
|
+
JSON encoding, deserialization, or conversion to Rust maps.
|
|
78
|
+
|
|
79
|
+
Run the Airspeed Velocity benchmarks against an equivalent Python implementation:
|
|
80
|
+
|
|
81
|
+
```sh
|
|
82
|
+
uv sync
|
|
83
|
+
uv run asv continuous --factor 1.15 --interleave-rounds --split HEAD^ HEAD
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Benchmarks check matching results before timing and cover flat dictionaries,
|
|
87
|
+
nested configuration, deep dictionaries, large lists, and list concatenation.
|
|
88
|
+
Both implementations copy dict/list containers and share opaque leaves. ASV
|
|
89
|
+
stores results in `.asv/results`; CI compares each pull request against its base
|
|
90
|
+
revision on the same runner and uploads the result files as a workflow artifact.
|
|
91
|
+
The 15% threshold filters small variations. Use release builds and measure your
|
|
92
|
+
own workload; Python allocation and key hashing still determine much of the cost.
|
|
93
|
+
|
|
94
|
+
See [local benchmark results](benchmarks/README.md) for measured timings and
|
|
95
|
+
the machine and sampling conditions.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"project": "weaved",
|
|
4
|
+
"project_url": "https://github.com/cetanu/weaved",
|
|
5
|
+
"repo": ".",
|
|
6
|
+
"branches": ["master"],
|
|
7
|
+
"show_commit_url": "",
|
|
8
|
+
"environment_type": "virtualenv",
|
|
9
|
+
"pythons": ["3.14"],
|
|
10
|
+
"env_dir": ".asv/env",
|
|
11
|
+
"benchmark_dir": "benchmarks/asv",
|
|
12
|
+
"results_dir": ".asv/results",
|
|
13
|
+
"html_dir": ".asv/html",
|
|
14
|
+
"build_command": [
|
|
15
|
+
"python -m pip wheel --no-deps --wheel-dir {build_cache_dir} {build_dir}"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Local benchmark results
|
|
2
|
+
|
|
3
|
+
Measured on 2026-10-02 with CPython 3.14.0, Rust 1.98.1, Linux x86-64,
|
|
4
|
+
and an AMD Ryzen 7 9800X3D. Weave was compiled in release mode. Both
|
|
5
|
+
implementations return independent dictionary/list containers and share opaque
|
|
6
|
+
leaves; each case checks equivalent results before timing.
|
|
7
|
+
|
|
8
|
+
| Workload | Weave | Python reference | Speedup |
|
|
9
|
+
| --- | ---: | ---: | ---: |
|
|
10
|
+
| Tiny dictionaries | 148 ns | 704 ns | 4.8× |
|
|
11
|
+
| Flat dictionaries, 10,000 keys each | 329 µs | 2,050 µs | 6.2× |
|
|
12
|
+
| Nested configuration, 100 services | 21.4 µs | 126 µs | 5.9× |
|
|
13
|
+
| Nested configuration with list concatenation | 22.8 µs | 152 µs | 6.7× |
|
|
14
|
+
| Deep dictionaries, 100 levels | 7.70 µs | 30.9 µs | 4.0× |
|
|
15
|
+
| Replace a list of 10,000 scalars | 14.7 µs | 574 µs | 39.1× |
|
|
16
|
+
| Concatenate lists of 10,000 scalars each | 30.6 µs | 1,170 µs | 38.1× |
|
|
17
|
+
| Concatenate lists of nested containers | 96.3 µs | 431 µs | 4.5× |
|
|
18
|
+
| Overwrite a nested subtree with `None` | 148 ns | 515 ns | 3.5× |
|
|
19
|
+
|
|
20
|
+
These are historical short local measurements from the original pyperf harness,
|
|
21
|
+
not performance guarantees or comparisons against other libraries. Pyperf
|
|
22
|
+
reported insufficient samples to establish variation below 1%. The Python
|
|
23
|
+
reference recursively visits scalar list elements; Weave uses native copies and
|
|
24
|
+
only recurses into containers, which accounts for the larger improvement on
|
|
25
|
+
scalar lists.
|
|
26
|
+
|
|
27
|
+
The maintained Airspeed Velocity suite runs each implementation on the same
|
|
28
|
+
workloads and compares revisions statistically. Run it from the project root:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
uv run asv continuous --factor 1.15 --interleave-rounds --split HEAD^ HEAD
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
ASV stores benchmark records in `.asv/results`. After editing Rust, ASV builds
|
|
35
|
+
the selected revision in release mode before measuring it.
|
|
File without changes
|