Repository navigation
Fix 1983 - #1984
Fix 1983#1984
Conversation
…uffers or numpy New src/autobahn/test/test_import_websocket_only.py (runs under both trial and pytest). Each import runs in a fresh interpreter, with a fake "numpy" package first on the path, so the tests do not depend on whether numpy is installed: - importing autobahn, autobahn.twisted.websocket or autobahn.asyncio.websocket must load neither the vendored FlatBuffers runtime nor numpy - with a broken numpy (raises ImportError), the same imports must succeed - after a WebSocket-only import, FlatBuffers still works when used (serializer roundtrip) Expected: the first two fail on master (autobahn/__init__.py and autobahn/wamp/message.py import the FlatBuffers runtime eagerly, which imports numpy whenever installed), the third passes. Note: This work was completed with AI assistance (Claude Code).
… interpreters `just test-imports` now also runs src/autobahn/test/test_import_websocket_only.py. CI calls it in the "Import Smoke Test" job for cpy311, cpy312, cpy313, cpy314 and pypy311, so the new tests also run on PyPy (the main test job runs them on cpy314 only, via test-twisted and test-asyncio). Expected: test_no_flatbuffers_no_numpy and test_broken_numpy_does_not_break_import fail on all five interpreters. Note: This work was completed with AI assistance (Claude Code).
TDD phase 1: redThis PR fixes #1983 test-first: first the red commits, which only add tests and must fail on Red commit 1:
|
…t is used Importing autobahn for WebSocket only (Twisted or asyncio) no longer loads the vendored FlatBuffers runtime, nor numpy, which that runtime imports at module level whenever installed. A broken numpy install can no longer make autobahn unimportable for WebSocket users. - autobahn/__init__.py: move "from autobahn import flatbuffers" from module level into check_zlmdb_flatbuffers_version_in_sync(), the only user, next to its existing local "import zlmdb.flatbuffers". - autobahn/wamp/message.py: import "autobahn.flatbuffers" and "autobahn.wamp.message_fbs" through importlib.util.LazyLoader (the "Implementing lazy imports" recipe from the importlib docs), so they are executed on the first FlatBuffers message built or parsed. No test changes: the red tests from the previous two commits now pass, on CPython 3.14 and PyPy 3.11 (35 passed, 6 subtests passed). Note: This work was completed with AI assistance (Claude Code).
TDD phase 2: greenGreen commit:
|
| job | red (9ca0d0bb) |
green (8077fcb0) |
|---|---|---|
| Import Smoke Test (cpy314), CPython 3.14.8 | 6 failed, 35 passed | 35 passed |
| Import Smoke Test (cpy313), CPython 3.13.16 | cancelled | 35 passed |
| Import Smoke Test (cpy312), CPython 3.12.3 | cancelled | 35 passed |
| Import Smoke Test (cpy311), CPython 3.11.17 | cancelled | 35 passed |
| Import Smoke Test (pypy311), PyPy 3.11.15 | cancelled (6 failed, 35 passed locally) | 35 passed |
| Code Quality Checks: coverage, Twisted / trial (with NVX) | FAILED (skips=32, failures=2, successes=326) |
PASSED (skips=32, successes=328) |
| Code Quality Checks: coverage, Twisted / trial (without NVX) | not run | PASSED (skips=31, successes=329) |
| Code Quality Checks: coverage, asyncio / pytest | not run | 298 passed, 6 skipped / 299 passed, 5 skipped |
All three new tests pass under both trial and pytest, and on all five interpreters, PyPy
included. So with the fix:
import autobahn,import autobahn.twisted.websocketandimport autobahn.asyncio.websocketload
neither the FlatBuffers runtime nor numpy (goal 3).- The same imports succeed when numpy is installed but broken.
- FlatBuffers serialization still works, and still loads the runtime when used (goal 1).
check_zlmdb_flatbuffers_version_in_sync() (goal 2) keeps its name and behaviour. Locally, against
zlmdb 26.7.1, it returns 25.12.19 as before.
Memory
Measured locally, as peak RSS (VmHWM) right after the import in a fresh interpreter, median of 5
runs, with numpy installed. † means numpy was loaded.
| import | CPython 3.14: 26.7.1 → this PR | PyPy 3.11: 26.7.1 → this PR |
|---|---|---|
import autobahn |
28.7 MB † → 11.9 MB | 87.9 MB † → 64.4 MB |
import autobahn.asyncio.websocket |
51.0 MB † → 37.7 MB | 117.0 MB † → 99.2 MB |
import autobahn.twisted.websocket |
63.0 MB † → 50.1 MB | 132.3 MB † → 113.7 MB |
from daphne.server import Server |
64.4 MB † → 51.5 MB | 135.9 MB † → 115.5 MB |
The full tables, the method, and the scripts to reproduce them follow in a separate docs commit on
this PR (docs/memory-footprint.rst, scripts/memory-footprint/).
Note: This comment was drafted with AI assistance (Claude Code).
…e and after New docs page docs/memory-footprint.rst (linked after wheels-inventory): peak RSS (VmHWM) right after an import, in a fresh interpreter, for CPython 3.14 and PyPy 3.11, comparing autobahn 25.10.2 (FlatBuffers optional), 26.7.1 (vendored FlatBuffers, loaded eagerly) and this branch. Rows: the interpreter, cryptography, numpy, asyncio, Twisted, txaio, autobahn (WAMP and WebSocket imports), Daphne and Crossbar.io. With the fix, every autobahn import drops by about 13-17 MB on CPython and 18-24 MB on PyPy, and none loads numpy any more. - scripts/memory-footprint/measure.py: measures the venv it runs in - scripts/memory-footprint/run.sh: creates throwaway venvs (uv) per autobahn version, plus a crossbar venv, and runs measure.py in each - scripts/memory-footprint/render.py: renders the results as the included tables (docs/memory-footprint/*.inc) - scripts/memory-footprint/results/: the raw results the page shows - justfile: "just memory-footprint <cpy314|pypy311> [label]" Note: This work was completed with AI assistance (Claude Code).
Next release is 26.10.1 (26.9.1 is not released, superseded). Note: This work was completed with AI assistance (Claude Code).
…1.dev1 Re-measured after the version bump, so the recorded versions match the development version. Values within measurement noise of the previous run. Note: This work was completed with AI assistance (Claude Code).
fixes #1983 - with proper two-phase, red-green TDD