Make normal signing ~30× faster; add opt-in batching - #165
Draft
josusanmartin wants to merge 3 commits into
Draft
Conversation
This was referenced Aug 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Result: ~30× faster normal
sign_create_orderNormal single-order latency: 1.95–2.02 ms → 63.9 µs
Sequential signing throughput: roughly 500 → 15,700 orders/sec
That is approximately 96.7% less latency without changing the public API.
This is the ordinary one-order-at-a-time public API. It requires no batching and no prepared nonces. The normal-path speedup is the purpose of this PR; the explicit batch API is a secondary, opt-in improvement.
The 1.95–2.02 ms baseline is the original warm end-to-end caller measurement on this host. The 63.9 µs result is the public Python signing call with the linked Go and Poseidon changes over 7 × 1,000 sequential orders. Against the currently bundled signer's directly measured 1,644 µs public Python path, it is still 25.7× faster.
Summary
Speed up the ordinary single-order Python signing path, while remaining compatible with older packaged signer binaries.
C.CStringresults directly through the process allocator on POSIX, avoiding extra Python-to-Go callbacksFreeon Windows, where allocation can cross CRT heapsWith the currently bundled Linux signer, changing only response cleanup reduced the public single-order path from 1,644 µs/order to 816.5 µs/order (median, 5 × 500 orders). With the linked Go and Poseidon PRs, the normal public call measured 63.9 µs/order (median, 7 × 1,000 orders), or about 15.7k orders/sec on the same Intel Xeon E-2286G host.
Important
The largest C-to-Go boundary reduction in the linked Go PR requires the private Go
_cgo_getstackboundhook. It is unsupported runtime internals, version-gated, and must be revalidated before upgrading the Go toolchain. This Python wrapper treats it as optional and continues to work when the export is absent or disabled.Secondary: explicit batching and prepared nonces
The new
sign_create_orders_batchmethod is opt-in. A normalsign_create_ordercall does not batch. The method uses one packed native response allocation, validates the explicit nonce range before either the native or legacy fallback path, and checks that the native result count matches the request count.On batches of 1,000 orders:
Prepared nonces are held in a process-global, in-memory pool by the linked Go signer. They are single-use and must not be persisted, serialized, or shared across a fork.
This PR also fixes the existing
CreateOrderTxReq.MarketIndexctypes field from 32-bit to the native ABI's 16-bit width in a separate commit.Packaging / merge order
No generated signer binaries are changed in this draft. Please merge/tag the Poseidon PR, update/merge the Go signer PR, regenerate all platform binaries, and then merge this wrapper PR.
Validation
pytest -q(80 passed)flake8error checks