Skip to content

Commit b950b43

Browse files
authored
Merge pull request #3 from TkTech/nanobind
[Experiment] Switching from pybind11 to nanobind for function call overhead improvements
2 parents 8c56ebe + 8f28e02 commit b950b43

10 files changed

Lines changed: 217 additions & 246 deletions

File tree

.github/workflows/release.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ jobs:
1313
name: Creating source release
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v4.1.1
16+
- uses: actions/checkout@v6.0.2
1717

1818
- name: Setting up Python
19-
uses: actions/setup-python@v5.4.0
19+
uses: actions/setup-python@v6.2.0
2020
with:
21-
python-version: 3.9
21+
python-version: "3.9"
2222

2323
- name: Installing python build dependencies
2424
run: |
@@ -35,7 +35,7 @@ jobs:
3535
run: |
3636
pytest
3737
38-
- uses: actions/upload-artifact@v4.3.1
38+
- uses: actions/upload-artifact@v6.0.0
3939
with:
4040
name: dist-sdist
4141
path: dist/*.tar.gz
@@ -50,32 +50,32 @@ jobs:
5050
strategy:
5151
fail-fast: true
5252
matrix:
53-
os: [ubuntu-22.04, windows-2022, macos-13]
54-
py: ["cp39", "cp310", "cp311", "cp312", "cp313"]
53+
os: [ubuntu-22.04, windows-2022, macos-15]
54+
py: ["cp39", "cp310", "cp311", "cp312", "cp313", "cp314"]
5555

5656
steps:
57-
- uses: actions/checkout@v4.1.1
57+
- uses: actions/checkout@v6.0.2
5858

59-
- uses: actions/setup-python@v5.4.0
59+
- uses: actions/setup-python@v6.2.0
6060
name: Setting up Python
6161
with:
62-
python-version: '3.9'
62+
python-version: "3.9"
6363

6464
- name: Set up QEMU
6565
if: runner.os == 'Linux'
66-
uses: docker/setup-qemu-action@v1
66+
uses: docker/setup-qemu-action@v3.7.0
6767
with:
6868
platforms: all
6969

7070
- name: Build & test wheels
71-
uses: pypa/cibuildwheel@v2.22.0
71+
uses: pypa/cibuildwheel@v3.3.1
7272
env:
7373
CIBW_ARCHS_LINUX: auto aarch64 ppc64le s390x
7474
CIBW_ARCHS_MACOS: x86_64 arm64 universal2
7575
CIBW_BUILD: "${{ matrix.py }}-*"
7676
CIBW_TEST_SKIP: "*_arm64 *_universal2:arm64"
7777

78-
- uses: actions/upload-artifact@v4.3.1
78+
- uses: actions/upload-artifact@v6.0.0
7979
with:
8080
name: dist-${{ matrix.os }}-${{ matrix.py }}
8181
path: ./wheelhouse/*.whl
@@ -85,13 +85,13 @@ jobs:
8585
name: Uploading built packages to pypi for release.
8686
runs-on: ubuntu-latest
8787
steps:
88-
- uses: actions/download-artifact@v4.1.4
88+
- uses: actions/download-artifact@v7.0.0
8989
with:
9090
pattern: dist-*
9191
merge-multiple: true
9292
path: dist
9393

94-
- uses: pypa/gh-action-pypi-publish@v1.8.14
94+
- uses: pypa/gh-action-pypi-publish@v1.13.0
9595
with:
9696
user: ${{ secrets.PYPI_USERNAME }}
9797
password: ${{ secrets.PYPI_PASSWORD }}

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ jobs:
1515
strategy:
1616
fail-fast: false
1717
matrix:
18-
os: [ubuntu-22.04, macos-13, windows-2022]
19-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
18+
os: [ubuntu-22.04, macos-15, windows-2022]
19+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
2020

2121
steps:
22-
- uses: actions/checkout@v4.1.1
22+
- uses: actions/checkout@v6.0.2
2323

2424
- name: Set up Python ${{ matrix.python-version }}
25-
uses: actions/setup-python@v5.0.0
25+
uses: actions/setup-python@v6.2.0
2626
with:
2727
python-version: ${{ matrix.python-version }}
2828

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 3.15...3.30)
2+
project(can_ada LANGUAGES CXX)
3+
4+
set(CMAKE_CXX_STANDARD 17)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
6+
7+
find_package(Python REQUIRED COMPONENTS Interpreter Development.Module)
8+
find_package(nanobind CONFIG REQUIRED)
9+
10+
nanobind_add_module(can_ada src/binding.cpp src/ada.cpp)
11+
target_compile_definitions(can_ada PRIVATE VERSION_INFO=${SKBUILD_PROJECT_VERSION})
12+
13+
install(TARGETS can_ada LIBRARY DESTINATION .)

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ C++17-or-greater compiler will be required to build the underlying Ada library.
1414

1515
## WHATWG URL compliance
1616

17-
Unlike the standard library's `urllib.parse` module, this library is compliant with the WHATWG URL specification.
17+
Unlike the standard library's `urllib.parse` module, this library is compliant
18+
with the WHATWG URL specification.
1819

1920
```python
2021
import can_ada
@@ -82,13 +83,14 @@ print(params.values()) # ["usa", "off", "2", "3"]
8283
We find that `can_ada` is typically ~4x faster than urllib:
8384

8485
```
85-
---------------------------------------------------------------------------------
86-
Name (time in ms) Min Max Mean
87-
---------------------------------------------------------------------------------
88-
test_can_ada_parse 54.1304 (1.0) 54.6734 (1.0) 54.3699 (1.0)
89-
test_ada_python_parse 107.5653 (1.99) 108.1666 (1.98) 107.7817 (1.98)
90-
test_urllib_parse 251.5167 (4.65) 255.1327 (4.67) 253.2407 (4.66)
91-
---------------------------------------------------------------------------------
86+
------------------------------------------------------------------------------------- benchmark: 4 tests ------------------------------------------------------------------------------------
87+
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
88+
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
89+
test_can_ada_parse 36.7565 (1.0) 40.3057 (1.0) 37.1606 (1.0) 0.6789 (1.0) 36.9869 (1.0) 0.2526 (1.0) 2;3 26.9102 (1.0) 27 1
90+
test_ada_python_parse 134.0627 (3.65) 143.6443 (3.56) 135.8992 (3.66) 3.1977 (4.71) 134.7860 (3.64) 1.2441 (4.92) 1;1 7.3584 (0.27) 8 1
91+
test_urllib_parse 208.8403 (5.68) 212.9208 (5.28) 211.2021 (5.68) 1.7273 (2.54) 211.3141 (5.71) 2.9319 (11.60) 1;0 4.7348 (0.18) 5 1
92+
test_yarl_parse 238.6351 (6.49) 246.4206 (6.11) 242.4351 (6.52) 3.4108 (5.02) 241.8302 (6.54) 6.1566 (24.37) 2;0 4.1248 (0.15) 5 1
93+
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
9294
```
9395

9496
To run the benchmarks locally, use:
@@ -97,4 +99,4 @@ To run the benchmarks locally, use:
9799
pytest --runslow
98100
```
99101

100-
[Ada]: https://ada-url.com/
102+
[Ada]: https://ada-url.com/

pyproject.toml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
[build-system]
2-
requires = [
3-
"setuptools>=42",
4-
"pybind11>=2.10.0",
5-
]
6-
build-backend = "setuptools.build_meta"
2+
requires = ["scikit-build-core>=0.10", "nanobind>=2.0.0"]
3+
build-backend = "scikit_build_core.build"
4+
5+
[project]
6+
name = "can_ada"
7+
version = "3.0.0"
8+
description = "Ada is a fast spec-compliant url parser"
9+
readme = "README.md"
10+
license = "MIT"
11+
authors = [{ name = "Tyler Kennedy", email = "tk@tkte.ch" }]
12+
requires-python = ">=3.9"
13+
14+
[project.urls]
15+
Homepage = "https://github.com/tktech/can_ada"
16+
17+
[project.optional-dependencies]
18+
test = ["pytest", "pytest-benchmark", "ada_url", "yarl"]
19+
20+
[tool.scikit-build]
21+
wheel.packages = ["can_ada-stubs"]

setup.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)