Skip to content

Commit 133d6e5

Browse files
Merge pull request #9 from Chainscore/feat/speedup0226-rev
Feat/speedup0226 rev
2 parents bcb5946 + 77f392d commit 133d6e5

38 files changed

Lines changed: 4544 additions & 12045 deletions

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ jobs:
2525

2626
- name: Install dependencies
2727
run: |
28-
uv pip install --system setuptools wheel
2928
uv pip install --system -e ".[dev]"
30-
python setup.py build_ext --inplace
3129
3230
- name: Lint (ruff)
3331
run: |

.github/workflows/release.yml

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,16 @@ jobs:
3030

3131
- name: Install dependencies
3232
run: |
33-
uv pip install --system setuptools wheel
3433
uv pip install --system -e ".[dev]"
35-
python setup.py build_ext --inplace
3634
3735
- name: Run tests
3836
run: pytest tests/
3937

40-
build_wheels:
41-
name: Build wheels (${{ matrix.os }})
38+
build_wheel:
39+
name: Build pure Python wheel
4240
needs: test
43-
if: github.event_name != 'pull_request' || startsWith(github.head_ref, 'fix/build-')
44-
runs-on: ${{ matrix.os }}
45-
strategy:
46-
fail-fast: false
47-
matrix:
48-
os: [ubuntu-latest, macos-latest]
49-
41+
runs-on: ubuntu-latest
42+
if: startsWith(github.ref, 'refs/tags/v')
5043
steps:
5144
- uses: actions/checkout@v4
5245

@@ -55,12 +48,6 @@ jobs:
5548
with:
5649
python-version: "3.12"
5750

58-
- name: Set up QEMU (for aarch64 wheels)
59-
if: runner.os == 'Linux'
60-
uses: docker/setup-qemu-action@v3
61-
with:
62-
platforms: arm64
63-
6451
- name: Set up uv
6552
uses: astral-sh/setup-uv@v3
6653
with:
@@ -112,22 +99,16 @@ jobs:
11299
print(f"Set version to {version}")
113100
PY
114101
115-
- name: Install cibuildwheel
116-
run: uv pip install --system cibuildwheel
117-
118-
- name: Build wheels
119-
run: python -m cibuildwheel --output-dir wheelhouse
120-
env:
121-
CIBW_BUILD: "cp312-*"
122-
CIBW_SKIP: "*musllinux*"
123-
CIBW_ARCHS_LINUX: "x86_64 aarch64"
124-
CIBW_ARCHS_MACOS: "x86_64 arm64"
102+
- name: Build wheel
103+
run: |
104+
uv pip install --system build
105+
python -m build --wheel --outdir dist
125106
126-
- name: Upload wheels
107+
- name: Upload wheel
127108
uses: actions/upload-artifact@v4
128109
with:
129-
name: wheels-${{ matrix.os }}
130-
path: wheelhouse/*.whl
110+
name: wheel
111+
path: dist/*.whl
131112

132113
build_sdist:
133114
name: Build sdist
@@ -207,18 +188,17 @@ jobs:
207188
publish_pypi:
208189
name: Publish to PyPI
209190
runs-on: ubuntu-latest
210-
needs: [build_wheels, build_sdist]
191+
needs: [build_wheel, build_sdist]
211192
if: startsWith(github.ref, 'refs/tags/v')
212193
permissions:
213194
id-token: write
214195
contents: write
215196
steps:
216-
- name: Download wheels
197+
- name: Download wheel
217198
uses: actions/download-artifact@v4
218199
with:
219-
pattern: wheels-*
200+
name: wheel
220201
path: dist
221-
merge-multiple: true
222202

223203
- name: Download sdist
224204
uses: actions/download-artifact@v4

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ __pycache__/
55

66
# C extensions
77
*.so
8+
*.so.*
89

910
# Distribution / packaging
1011
.Python
@@ -227,6 +228,7 @@ $RECYCLE.BIN/
227228
# Project-specific
228229
.benchmarks/
229230
.ruff_cache/
231+
benchmarks/out/bench_profiles.json
230232

231233
# Publishing artifacts (for development only)
232234
.twine/

Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.PHONY: help clean build test rebuild install dev bench bench-compare bench-baseline
2+
3+
help:
4+
@echo "Available targets:"
5+
@echo " clean - Remove all build artifacts and compiled modules"
6+
@echo " build - Build C extensions in-place"
7+
@echo " rebuild - Clean and rebuild everything"
8+
@echo " test - Run pytest"
9+
@echo " install - Install package in development mode"
10+
@echo " dev - Clean, rebuild, and run tests"
11+
@echo ""
12+
@echo "Benchmarks:"
13+
@echo " bench - Run benchmarks"
14+
@echo " bench-compare - Compare with baseline"
15+
@echo " bench-baseline - Set current results as baseline"
16+
17+
clean:
18+
@echo "Cleaning build artifacts..."
19+
rm -rf build/ dist/ *.egg-info/ .pytest_cache/
20+
rm -f *.so *.dylib *.so.disabled
21+
rm -f tsrkit_types/*.so tsrkit_types/*.dylib tsrkit_types/*.so.disabled
22+
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
23+
find . -type f -name "*.pyc" -delete 2>/dev/null || true
24+
@echo "Clean complete."
25+
26+
build:
27+
@echo "Building C extensions..."
28+
python setup.py build_ext --inplace
29+
@echo "Build complete."
30+
31+
rebuild: clean build
32+
33+
test:
34+
@echo "Running tests..."
35+
uv run --frozen pytest
36+
37+
install:
38+
@echo "Installing in development mode..."
39+
uv pip install -e ".[dev]"
40+
41+
dev: rebuild test
42+
@echo "Development setup complete."
43+
44+
# Benchmarks
45+
bench:
46+
@uv run python benchmarks/bench_types.py --no-profile $(ARGS)
47+
48+
bench-compare:
49+
@python benchmarks/compare.py benchmarks/out/bench_results.json benchmarks/out/bench_baseline.json
50+
51+
bench-baseline:
52+
@cp benchmarks/out/bench_results.json benchmarks/out/bench_baseline.json
53+
@echo "✅ Baseline updated from bench_results.json"

benchmark.md

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,39 @@
11
# Benchmarks
22

3-
This document records the latest benchmark run and the Python/stdlib baselines used for comparison.
4-
All timings are **seconds for 20,000 runs** on the local machine; results are not directly comparable across hardware or Python versions.
3+
Compare performance between runs. All timings are **seconds for 20,000 runs**.
54

6-
## How To Run
5+
## Quick Start
76

87
```bash
9-
PYTHONPATH=. python3.12 benchmarks/bench_types.py
8+
make bench # Run benchmarks
9+
make bench-compare # Compare with baseline
10+
make bench-baseline # Set current as baseline
1011
```
1112

12-
Raw data is written to:
13-
- `benchmarks/out/bench_results.json`
14-
- `benchmarks/out/bench_profiles.json`
15-
16-
## Latest Results (Local)
17-
18-
**Run date:** 2026-02-04
19-
**Python:** 3.12.11
20-
**Runs:** 20,000
21-
22-
### TSRKit Types (selected)
23-
24-
| Case | init_s | encode_s | decode_s | json_encode_s | json_decode_s |
25-
| --- | --- | --- | --- | --- | --- |
26-
| Uint | 0.008567 | 0.004479 | 0.014276 | 0.002534 | 0.008913 |
27-
| U16 | 0.008530 | 0.004632 | 0.014242 | 0.002791 | 0.009892 |
28-
| Bytes(var,64B) | 0.004458 | 0.010630 | 0.008252 | 0.003609 | 0.010214 |
29-
| ByteArray | 0.003199 | 0.006915 | 0.006440 | 0.003522 | 0.009588 |
30-
| Bits(var,64b) | 0.011615 | 0.011080 | 0.016224 | 0.007608 | 0.024439 |
31-
| TypedArray[U16,10] | 0.014253 | 0.006967 | 0.017195 | 0.003189 | 0.152636 |
32-
| Dictionary[String,U16] | 0.023382 | 0.061991 | 0.149705 | 0.068052 | 0.179980 |
33-
34-
### Python/Stdlib Baselines (selected)
35-
36-
| Case | init_s | encode_s | decode_s |
37-
| --- | --- | --- | --- |
38-
| PyInt(varint) | 0.002778 | 0.006405 | 0.007207 |
39-
| PyU16(to_bytes) | 0.004112 | 0.003861 | 0.006797 |
40-
| PyBytes(var,64B) | 0.003516 | 0.005396 | 0.005538 |
41-
| PyByteArray(var,64B) | 0.003091 | 0.006694 | 0.006594 |
42-
| PyBits(var,64b) | 0.006438 | 0.088161 | 0.150918 |
43-
| PyArray('H',10) | 0.006611 | 0.008616 | 0.006599 |
44-
| PyDict[str,U16] | 0.003587 | 0.095823 | 0.077303 |
45-
46-
## Notes On Baselines
47-
48-
- `PyInt(varint)`: pure-Python varint encoder/decoder (same scheme as `Uint`).
49-
- `PyU16(to_bytes)`: `int.to_bytes` / `int.from_bytes` for fixed-width integers.
50-
- `PyBytes(var,64B)` / `PyByteArray(var,64B)`: length-prefixed bytes (varint length).
51-
- `PyBits(var,64b)`: list[bool] packed/unpacked to bytes in Python.
52-
- `PyArray('H',10)`: stdlib `array('H')` with `.tobytes()` / `.frombytes()`.
53-
- `PyDict[str,U16]`: sorted key encode; keys length-prefixed; values fixed 2-byte little-endian.
13+
Results: `benchmarks/out/bench_results.json` (14KB)
14+
15+
## Workflow
16+
17+
```bash
18+
# 1. Set baseline
19+
make bench
20+
make bench-baseline
21+
22+
# 2. Make changes...
23+
24+
# 3. Compare
25+
make bench
26+
make bench-compare
27+
```
28+
29+
## Custom runs
30+
31+
```bash
32+
make bench ARGS="--runs 1000 --no-profile"
33+
```
34+
35+
## What's Tested
36+
37+
**Types**: Integers, Bytes, Bits, Strings, Bool, Collections, Dictionary, Option, Choice, Enum, Structures
38+
39+
**Operations**: init, encode, decode, json_encode/decode, container ops (append/extend/pop/getitem)

0 commit comments

Comments
 (0)